Skip to content

Commit

Permalink
Merge pull request #12 from diggerhq/fix/cookie-hack
Browse files Browse the repository at this point in the history
Cookie hack on any url, not just provider
  • Loading branch information
ZIJ authored Aug 8, 2024
2 parents 66e277d + 93a8b80 commit 0d64f81
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/app/(dynamic-pages)/(login-pages)/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0d64f81

Please sign in to comment.