Commit 8a94aeb 1 parent c3d294f commit 8a94aeb Copy full SHA for 8a94aeb
File tree 4 files changed +77
-9
lines changed
src/supabase-clients/user
4 files changed +77
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { Database } from '@/lib/database.types' ;
2
2
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' ;
3
3
import { cookies } from 'next/headers' ;
4
+
5
+ type createRouteHandlerClientParams = NonNullable <
6
+ Parameters < typeof createRouteHandlerClient > [ 1 ]
7
+ > ;
8
+ type CookieOptions = createRouteHandlerClientParams [ 'cookieOptions' ] ;
9
+
10
+ const isDevelopment = process . env . NODE_ENV === 'development' ;
11
+
12
+ const optionalCookieOptions : CookieOptions = isDevelopment
13
+ ? undefined
14
+ : {
15
+ domain : '.digger.dev' ,
16
+ secure : false ,
17
+ path : '/' ,
18
+ sameSite : 'lax' ,
19
+ } ;
20
+
4
21
// Outstanding bug
5
22
//https://github.com/vercel/next.js/issues/45371
6
23
export const createSupabaseUserRouteHandlerClient = ( ) =>
@@ -9,10 +26,6 @@ export const createSupabaseUserRouteHandlerClient = () =>
9
26
cookies,
10
27
} ,
11
28
{
12
- options : {
13
- global : {
14
- fetch,
15
- } ,
16
- } ,
29
+ cookieOptions : optionalCookieOptions ,
17
30
} ,
18
31
) ;
Original file line number Diff line number Diff line change @@ -2,7 +2,28 @@ import { Database } from '@/lib/database.types';
2
2
import { createServerActionClient } from '@supabase/auth-helpers-nextjs' ;
3
3
import { cookies } from 'next/headers' ;
4
4
5
+ type createServerActionClientParams = NonNullable <
6
+ Parameters < typeof createServerActionClient > [ 1 ]
7
+ > ;
8
+ type CookieOptions = createServerActionClientParams [ 'cookieOptions' ] ;
9
+
10
+ const isDevelopment = process . env . NODE_ENV === 'development' ;
11
+
12
+ const optionalCookieOptions : CookieOptions = isDevelopment
13
+ ? undefined
14
+ : {
15
+ domain : '.digger.dev' ,
16
+ secure : false ,
17
+ path : '/' ,
18
+ sameSite : 'lax' ,
19
+ } ;
20
+
5
21
export const createSupabaseUserServerActionClient = ( ) =>
6
- createServerActionClient < Database > ( {
7
- cookies,
8
- } ) ;
22
+ createServerActionClient < Database > (
23
+ {
24
+ cookies,
25
+ } ,
26
+ {
27
+ cookieOptions : optionalCookieOptions ,
28
+ } ,
29
+ ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,22 @@ import { Database } from '@/lib/database.types';
2
2
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs' ;
3
3
import { cookies } from 'next/headers' ;
4
4
5
+ const isDevelopment = process . env . NODE_ENV === 'development' ;
6
+
7
+ type createServerComponentClientParams = NonNullable <
8
+ Parameters < typeof createServerComponentClient > [ 1 ]
9
+ > ;
10
+ type CookieOptions = createServerComponentClientParams [ 'cookieOptions' ] ;
11
+
12
+ const optionalCookieOptions : CookieOptions = isDevelopment
13
+ ? undefined
14
+ : {
15
+ domain : '.digger.dev' ,
16
+ secure : false ,
17
+ path : '/' ,
18
+ sameSite : 'lax' ,
19
+ } ;
20
+
5
21
export const createSupabaseUserServerComponentClient = ( ) =>
6
22
createServerComponentClient < Database > (
7
23
{
@@ -13,5 +29,6 @@ export const createSupabaseUserServerComponentClient = () =>
13
29
fetch,
14
30
} ,
15
31
} ,
32
+ cookieOptions : optionalCookieOptions ,
16
33
} ,
17
34
) ;
Original file line number Diff line number Diff line change 1
1
// https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components#creating-a-supabase-client
2
- import { createClientComponentClient } from '@supabase/auth-helpers-nextjs' ;
3
2
import { Database } from '@/lib/database.types' ;
3
+ import { createClientComponentClient } from '@supabase/auth-helpers-nextjs' ;
4
+
5
+ const isDevelopment = process . env . NODE_ENV === 'development' ;
6
+
7
+ type createClientComponentClientParams = NonNullable <
8
+ Parameters < typeof createClientComponentClient > [ 0 ]
9
+ > ;
10
+ type CookieOptions = createClientComponentClientParams [ 'cookieOptions' ] ;
11
+
12
+ const optionalCookieOptions : CookieOptions = isDevelopment
13
+ ? undefined
14
+ : {
15
+ domain : '.digger.dev' ,
16
+ secure : false ,
17
+ path : '/' ,
18
+ sameSite : 'lax' ,
19
+ } ;
4
20
5
21
// apologies for the name, but it's the best I could come up with as
6
22
// the util exported from @supabase /auth-helpers-nextjs is called
@@ -12,4 +28,5 @@ export const supabaseUserClientComponentClient =
12
28
fetch,
13
29
} ,
14
30
} ,
31
+ cookieOptions : optionalCookieOptions ,
15
32
} ) ;
You can’t perform that action at this time.
0 commit comments