From 93a8b80d6b77a899c577faf1ca63be32fccfae93 Mon Sep 17 00:00:00 2001 From: Igor Zalutski Date: Thu, 8 Aug 2024 16:22:27 +0400 Subject: [PATCH] Cookie hack on any url, not just provider --- .../(login-pages)/auth/callback/route.ts | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/app/(dynamic-pages)/(login-pages)/auth/callback/route.ts b/src/app/(dynamic-pages)/(login-pages)/auth/callback/route.ts index d091374b..9c698a2f 100644 --- a/src/app/(dynamic-pages)/(login-pages)/auth/callback/route.ts +++ b/src/app/(dynamic-pages)/(login-pages)/auth/callback/route.ts @@ -22,30 +22,26 @@ export async function GET(request: Request) { } } - if (provider) { - // HACK_ALERT!!! - // cookie is probably set on 'next.digger.dev' we have to change it to `.digger.dev` - const cookieKey = `sb-${process.env.SUPABASE_PROJECT_REF}-auth-token`; - const cookieStore = cookies(); - const currentCookieValue = cookieStore.get(cookieKey)?.value; - // get domain of current reques - const domain = new URL(request.url).hostname; - if ( - domain.includes('next.digger.dev') && - currentCookieValue && - !isDevelopment - ) { - // delete cookie from next.digger.dev - cookieStore.delete(cookieKey); - // set cookie to .digger.dev - cookieStore.set(cookieKey, currentCookieValue, { - domain: '.digger.dev', - secure: true, - path: '/', - sameSite: 'lax', - httpOnly: true, - }); - } + // HACK_ALERT!!! + // cookie is probably set on 'next.digger.dev' we have to change it to `.digger.dev` + const cookieKey = `sb-${process.env.SUPABASE_PROJECT_REF}-auth-token`; + const cookieStore = cookies(); + const currentCookieValue = cookieStore.get(cookieKey)?.value; + // get domain of current reques + const domain = new URL(request.url).hostname; + if ( + domain.includes('next.digger.dev') && + currentCookieValue && + !isDevelopment + ) { + // set cookie to .digger.dev + cookieStore.set(cookieKey, currentCookieValue, { + domain: '.digger.dev', + secure: true, + path: '/', + sameSite: 'lax', + httpOnly: true, + }); } let redirectTo = new URL('/dashboard', requestUrl.origin);