From 9d0721c4f95bceb14f5557dec4e2fc30e4ba5c5a Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Mon, 7 Nov 2022 19:20:57 +0800 Subject: [PATCH] [portal][feat] configure Next Auth's sign in route to point to custom login page --- apps/portal/src/components/shared/loginPageHref.ts | 2 +- apps/portal/src/pages/api/auth/[...nextauth].ts | 3 +++ apps/portal/src/pages/login.tsx | 4 ++-- apps/portal/src/pages/settings.tsx | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/portal/src/components/shared/loginPageHref.ts b/apps/portal/src/components/shared/loginPageHref.ts index bf505b4e..d3a8d2bb 100644 --- a/apps/portal/src/components/shared/loginPageHref.ts +++ b/apps/portal/src/components/shared/loginPageHref.ts @@ -2,7 +2,7 @@ export default function loginPageHref(redirectUrl?: string) { return { pathname: '/login', query: { - redirect: + callbackUrl: typeof window !== 'undefined' ? redirectUrl ?? window.location.href : null, diff --git a/apps/portal/src/pages/api/auth/[...nextauth].ts b/apps/portal/src/pages/api/auth/[...nextauth].ts index e297c6f9..03954774 100644 --- a/apps/portal/src/pages/api/auth/[...nextauth].ts +++ b/apps/portal/src/pages/api/auth/[...nextauth].ts @@ -20,6 +20,9 @@ export const authOptions: NextAuthOptions = { return session; }, }, + pages: { + signIn: '/login', + }, providers: [ GitHubProvider({ clientId: env.GITHUB_CLIENT_ID, diff --git a/apps/portal/src/pages/login.tsx b/apps/portal/src/pages/login.tsx index 28b3088a..bcc4262c 100644 --- a/apps/portal/src/pages/login.tsx +++ b/apps/portal/src/pages/login.tsx @@ -54,9 +54,9 @@ export default function LoginPage({ onClick={() => signIn( provider.id, - router.query.redirect != null + router.query.callbackUrl != null ? { - callbackUrl: String(router.query.redirect), + callbackUrl: String(router.query.callbackUrl), } : undefined, ) diff --git a/apps/portal/src/pages/settings.tsx b/apps/portal/src/pages/settings.tsx index a7d112d3..e8c3c3b5 100644 --- a/apps/portal/src/pages/settings.tsx +++ b/apps/portal/src/pages/settings.tsx @@ -127,7 +127,7 @@ export default function SettingsPage() { } if (session == null) { - return null; + return

You are not signed in

; } return (