Skip to content

Commit 9c30ba1

Browse files
authored
Implement DEFAULT_HOMEPAGE env var for redirect (#280)
* Add DEFAULT_HOMEPAGE env var * Remove duplicated head fields * Dont use home as index page * Create a redirect to custom homepage * Update the env example message
1 parent 5325fcf commit 9c30ba1

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_CONT
1919
NEXTAUTH_SECRET="secret"
2020
NEXTAUTH_URL="http://localhost:3000"
2121

22+
# The default /home page is a blog page that may not be suitable for your use case.
23+
# You can change it to /balances or any other URL you want.
24+
# Note that it creates a permanent redirect, so changing it later will require a cache clear from users.
25+
DEFAULT_HOMEPAGE="/home"
26+
2227
# If provided, server-side calls will use this instead of NEXTAUTH_URL.
2328
# Useful in environments when the server doesn't have access to the canonical URL
2429
# of your site.

next.config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
66
* for Docker builds.
77
*/
8-
await import('./src/env.js');
9-
10-
/** @type {import("next").NextConfig} */
11-
128
import pwa from 'next-pwa';
139
// @ts-ignore
1410
import nextra from 'nextra';
@@ -19,6 +15,7 @@ const withPwa = pwa({
1915
// disable: process.env.NODE_ENV === 'development',
2016
});
2117

18+
/** @type {import("next").NextConfig} */
2219
const config = {
2320
reactStrictMode: true,
2421
output: process.env.DOCKER_OUTPUT ? 'standalone' : undefined,
@@ -35,6 +32,13 @@ const config = {
3532
defaultLocale: 'en',
3633
},
3734
transpilePackages: ['geist'],
35+
redirects: async () => [
36+
{
37+
source: '/',
38+
destination: process.env.DEFAULT_HOMEPAGE ?? '/home',
39+
permanent: true,
40+
},
41+
],
3842
images: {
3943
remotePatterns: [
4044
{

src/env.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const env = createEnv({
4949
WEB_PUSH_PUBLIC_KEY: z.string().optional(),
5050
FEEDBACK_EMAIL: z.string().optional(),
5151
DISCORD_WEBHOOK_URL: z.string().optional(),
52+
DEFAULT_HOMEPAGE: z.string().default('/home'),
5253
},
5354

5455
/**
@@ -92,6 +93,7 @@ export const env = createEnv({
9293
WEB_PUSH_PUBLIC_KEY: process.env.WEB_PUSH_PUBLIC_KEY,
9394
FEEDBACK_EMAIL: process.env.FEEDBACK_EMAIL,
9495
DISCORD_WEBHOOK_URL: process.env.DISCORD_WEBHOOK_URL,
96+
DEFAULT_HOMEPAGE: process.env.DEFAULT_HOMEPAGE,
9597
},
9698
/**
9799
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially

src/pages/auth/signin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
223223
if (session) {
224224
return {
225225
redirect: {
226-
destination: callbackUrl && !Array.isArray(callbackUrl) ? callbackUrl : '/balances',
226+
destination:
227+
callbackUrl && !Array.isArray(callbackUrl) ? callbackUrl : env.DEFAULT_HOMEPAGE,
227228
permanent: false,
228229
},
229230
};
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export default function Home() {
2121
return (
2222
<>
2323
<Head>
24-
<title>SplitPro: Split Expenses with your friends for free</title>
25-
<meta name="description" content="SplitPro: Split Expenses with your friends for free" />
26-
<link rel="icon" href="/favicon.ico" />
2724
{process.env.NODE_ENV === 'production' && (
2825
<>
2926
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>

0 commit comments

Comments
 (0)