1
- import { cookies } from ' next/headers'
2
- import { NextResponse } from ' next/server'
3
- import { type CookieOptions , createServerClient } from ' @supabase/ssr'
1
+ import { cookies } from " next/headers" ;
2
+ import { NextResponse } from " next/server" ;
3
+ import { type CookieOptions , createServerClient } from " @supabase/ssr" ;
4
4
5
5
export async function GET ( request : Request ) {
6
- const { searchParams, origin } = new URL ( request . url )
7
- const code = searchParams . get ( ' code' )
6
+ const { searchParams, origin } = new URL ( request . url ) ;
7
+ const code = searchParams . get ( " code" ) ;
8
8
// if "next" is in param, use it as the redirect URL
9
- const next = searchParams . get ( ' next' ) ?? '/'
9
+ const next = searchParams . get ( " next" ) ?? "/" ;
10
10
11
11
if ( code ) {
12
- const cookieStore = cookies ( )
12
+ const cookieStore = cookies ( ) ;
13
13
const supabase = createServerClient (
14
14
process . env . NEXT_PUBLIC_SUPABASE_URL ! ,
15
15
process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ! ,
16
16
{
17
17
cookies : {
18
18
get ( name : string ) {
19
- return cookieStore . get ( name ) ?. value
19
+ return cookieStore . get ( name ) ?. value ;
20
20
} ,
21
21
set ( name : string , value : string , options : CookieOptions ) {
22
- cookieStore . set ( { name, value, ...options } )
22
+ cookieStore . set ( { name, value, ...options } ) ;
23
23
} ,
24
24
remove ( name : string , options : CookieOptions ) {
25
- cookieStore . delete ( { name, ...options } )
25
+ cookieStore . delete ( { name, ...options } ) ;
26
26
} ,
27
27
} ,
28
- }
29
- )
30
- const { error } = await supabase . auth . exchangeCodeForSession ( code )
28
+ } ,
29
+ ) ;
30
+ const { error } = await supabase . auth . exchangeCodeForSession ( code ) ;
31
31
if ( ! error ) {
32
- return NextResponse . redirect ( `${ origin } ${ next } ` )
32
+ return NextResponse . redirect ( `${ origin } ${ next } ` ) ;
33
33
}
34
34
}
35
35
36
36
// return the user to an error page with instructions
37
- return NextResponse . redirect ( `${ origin } /auth/auth-code-error` )
38
- }
37
+ return NextResponse . redirect ( `${ origin } /auth/auth-code-error` ) ;
38
+ }
0 commit comments