1
1
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' ;
2
- import { revalidatePath } from 'next/cache' ;
3
2
import { cookies } from 'next/headers' ;
4
3
import { NextResponse } from 'next/server' ;
5
4
5
+ const isDevelopment = process . env . NODE_ENV === 'development' ;
6
+
6
7
export async function GET ( request : Request ) {
7
8
const requestUrl = new URL ( request . url ) ;
8
9
const code = requestUrl . searchParams . get ( 'code' ) ;
9
10
const next = requestUrl . searchParams . get ( 'next' ) ;
11
+ const provider = requestUrl . searchParams . get ( 'provider' ) ;
10
12
11
13
if ( code ) {
12
14
const supabase = createRouteHandlerClient ( { cookies } ) ;
@@ -19,7 +21,33 @@ export async function GET(request: Request) {
19
21
// Potentially return an error response here
20
22
}
21
23
}
22
- revalidatePath ( '/' , 'layout' ) ;
24
+
25
+ if ( provider ) {
26
+ // HACK_ALERT!!!
27
+ // cookie is probably set on 'next.digger.dev' we have to change it to `.digger.dev`
28
+ const cookieKey = `sb-${ process . env . SUPABASE_PROJECT_REF } -auth-token` ;
29
+ const cookieValue = cookies ( ) . get ( cookieKey ) ?. value ;
30
+ const cookieStore = cookies ( ) ;
31
+ const currentCookieValue = cookieStore . get ( cookieKey ) ?. value ;
32
+ // get domain of current reques
33
+ const domain = new URL ( request . url ) . hostname ;
34
+ if (
35
+ domain . includes ( 'next.digger.dev' ) &&
36
+ currentCookieValue &&
37
+ ! isDevelopment
38
+ ) {
39
+ // delete cookie from next.digger.dev
40
+ cookieStore . delete ( cookieKey ) ;
41
+ // set cookie to .digger.dev
42
+ cookieStore . set ( cookieKey , currentCookieValue , {
43
+ domain : '.digger.dev' ,
44
+ secure : true ,
45
+ path : '/' ,
46
+ sameSite : 'lax' ,
47
+ httpOnly : true ,
48
+ } ) ;
49
+ }
50
+ }
23
51
24
52
let redirectTo = new URL ( '/dashboard' , requestUrl . origin ) ;
25
53
0 commit comments