From 0a862ca770809fae13f4beefe441003505e98013 Mon Sep 17 00:00:00 2001 From: Michael Zetterberg Date: Tue, 14 May 2024 16:32:17 +0200 Subject: [PATCH] chore(debug): auth --- app/[lang]/(live)/(protected)/bypass/page.tsx | 7 ++ app/[lang]/(live)/(protected)/layout.tsx | 9 ++- app/[lang]/(live)/(public)/login/route.ts | 65 ++++++++++--------- 3 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 app/[lang]/(live)/(protected)/bypass/page.tsx diff --git a/app/[lang]/(live)/(protected)/bypass/page.tsx b/app/[lang]/(live)/(protected)/bypass/page.tsx new file mode 100644 index 000000000..9f37aa2a7 --- /dev/null +++ b/app/[lang]/(live)/(protected)/bypass/page.tsx @@ -0,0 +1,7 @@ +import { auth } from "@/auth" + +export default async function ByPass() { + const session = await auth() + + return
{JSON.stringify(session, null, 2)}
+} diff --git a/app/[lang]/(live)/(protected)/layout.tsx b/app/[lang]/(live)/(protected)/layout.tsx index 28849ab99..9f10ffc48 100644 --- a/app/[lang]/(live)/(protected)/layout.tsx +++ b/app/[lang]/(live)/(protected)/layout.tsx @@ -1,4 +1,6 @@ -import { auth, signIn } from "@/auth" +import { redirect } from "next/navigation" + +import { auth } from "@/auth" import type { LangParams, LayoutArgs } from "@/types/params" @@ -12,10 +14,7 @@ export default async function ProtectedLayout({ * protected route group is actually protected. */ if (!session) { - await signIn("curity", undefined, { - ui_locales: params.lang, - }) - return null + redirect(`/${params.lang}/login`) } return <>{children} diff --git a/app/[lang]/(live)/(public)/login/route.ts b/app/[lang]/(live)/(public)/login/route.ts index 7ba612ebd..c068992ca 100644 --- a/app/[lang]/(live)/(public)/login/route.ts +++ b/app/[lang]/(live)/(public)/login/route.ts @@ -47,38 +47,38 @@ export async function GET( "redirectTo=; Expires=Thu, 01 Jan 1970 00:00:00 UTC; Path=/; HttpOnly; SameSite=Lax" ) - try { - // Initiate the seamless login flow - let redirectUrlValue - switch (context.params.lang) { - case Lang.da: - redirectUrlValue = env.SEAMLESS_LOGIN_DA - break - case Lang.de: - redirectUrlValue = env.SEAMLESS_LOGIN_DE - break - case Lang.en: - redirectUrlValue = env.SEAMLESS_LOGIN_EN - break - case Lang.fi: - redirectUrlValue = env.SEAMLESS_LOGIN_FI - break - case Lang.no: - redirectUrlValue = env.SEAMLESS_LOGIN_NO - break - case Lang.sv: - redirectUrlValue = env.SEAMLESS_LOGIN_SV - break - } - const redirectUrl = new URL(redirectUrlValue) - redirectUrl.searchParams.set("returnurl", redirectTo) - redirectTo = redirectUrl.toString() - } catch (e) { - console.error( - "Unable to create URL for seamless login, proceeding without it." - ) - console.error(e) - } + // try { + // // Initiate the seamless login flow + // let redirectUrlValue + // switch (context.params.lang) { + // case Lang.da: + // redirectUrlValue = env.SEAMLESS_LOGIN_DA + // break + // case Lang.de: + // redirectUrlValue = env.SEAMLESS_LOGIN_DE + // break + // case Lang.en: + // redirectUrlValue = env.SEAMLESS_LOGIN_EN + // break + // case Lang.fi: + // redirectUrlValue = env.SEAMLESS_LOGIN_FI + // break + // case Lang.no: + // redirectUrlValue = env.SEAMLESS_LOGIN_NO + // break + // case Lang.sv: + // redirectUrlValue = env.SEAMLESS_LOGIN_SV + // break + // } + // const redirectUrl = new URL(redirectUrlValue) + // redirectUrl.searchParams.set("returnurl", redirectTo) + // redirectTo = redirectUrl.toString() + // } catch (e) { + // console.error( + // "Unable to create URL for seamless login, proceeding without it." + // ) + // console.error(e) + // } } try { @@ -101,6 +101,7 @@ export async function GET( ) console.log({ login_signInURL: signInURL }) + console.log({ login_redirectTo: redirectTo }) const redirectUrl = await signIn( "curity", {