diff --git a/src/supabase-clients/user/createSupabaseUserRouteHandlerClient.ts b/src/supabase-clients/user/createSupabaseUserRouteHandlerClient.ts index 94be0460..9d47bff1 100644 --- a/src/supabase-clients/user/createSupabaseUserRouteHandlerClient.ts +++ b/src/supabase-clients/user/createSupabaseUserRouteHandlerClient.ts @@ -1,6 +1,23 @@ import { Database } from '@/lib/database.types'; import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'; import { cookies } from 'next/headers'; + +type createRouteHandlerClientParams = NonNullable< + Parameters[1] +>; +type CookieOptions = createRouteHandlerClientParams['cookieOptions']; + +const isDevelopment = process.env.NODE_ENV === 'development'; + +const optionalCookieOptions: CookieOptions = isDevelopment + ? undefined + : { + domain: '.digger.dev', + secure: false, + path: '/', + sameSite: 'lax', + }; + // Outstanding bug //https://github.com/vercel/next.js/issues/45371 export const createSupabaseUserRouteHandlerClient = () => @@ -9,10 +26,6 @@ export const createSupabaseUserRouteHandlerClient = () => cookies, }, { - options: { - global: { - fetch, - }, - }, + cookieOptions: optionalCookieOptions, }, ); diff --git a/src/supabase-clients/user/createSupabaseUserServerActionClient.ts b/src/supabase-clients/user/createSupabaseUserServerActionClient.ts index 10c9f3fe..b76ffb8f 100644 --- a/src/supabase-clients/user/createSupabaseUserServerActionClient.ts +++ b/src/supabase-clients/user/createSupabaseUserServerActionClient.ts @@ -2,7 +2,28 @@ import { Database } from '@/lib/database.types'; import { createServerActionClient } from '@supabase/auth-helpers-nextjs'; import { cookies } from 'next/headers'; +type createServerActionClientParams = NonNullable< + Parameters[1] +>; +type CookieOptions = createServerActionClientParams['cookieOptions']; + +const isDevelopment = process.env.NODE_ENV === 'development'; + +const optionalCookieOptions: CookieOptions = isDevelopment + ? undefined + : { + domain: '.digger.dev', + secure: false, + path: '/', + sameSite: 'lax', + }; + export const createSupabaseUserServerActionClient = () => - createServerActionClient({ - cookies, - }); + createServerActionClient( + { + cookies, + }, + { + cookieOptions: optionalCookieOptions, + }, + ); diff --git a/src/supabase-clients/user/createSupabaseUserServerComponentClient.ts b/src/supabase-clients/user/createSupabaseUserServerComponentClient.ts index 896867e1..ec07b675 100644 --- a/src/supabase-clients/user/createSupabaseUserServerComponentClient.ts +++ b/src/supabase-clients/user/createSupabaseUserServerComponentClient.ts @@ -2,6 +2,22 @@ import { Database } from '@/lib/database.types'; import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; import { cookies } from 'next/headers'; +const isDevelopment = process.env.NODE_ENV === 'development'; + +type createServerComponentClientParams = NonNullable< + Parameters[1] +>; +type CookieOptions = createServerComponentClientParams['cookieOptions']; + +const optionalCookieOptions: CookieOptions = isDevelopment + ? undefined + : { + domain: '.digger.dev', + secure: false, + path: '/', + sameSite: 'lax', + }; + export const createSupabaseUserServerComponentClient = () => createServerComponentClient( { @@ -13,5 +29,6 @@ export const createSupabaseUserServerComponentClient = () => fetch, }, }, + cookieOptions: optionalCookieOptions, }, ); diff --git a/src/supabase-clients/user/supabaseUserClientComponentClient.ts b/src/supabase-clients/user/supabaseUserClientComponentClient.ts index b7dc219d..285578a3 100644 --- a/src/supabase-clients/user/supabaseUserClientComponentClient.ts +++ b/src/supabase-clients/user/supabaseUserClientComponentClient.ts @@ -1,6 +1,22 @@ // https://supabase.com/docs/guides/auth/auth-helpers/nextjs-server-components#creating-a-supabase-client -import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; import { Database } from '@/lib/database.types'; +import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; + +const isDevelopment = process.env.NODE_ENV === 'development'; + +type createClientComponentClientParams = NonNullable< + Parameters[0] +>; +type CookieOptions = createClientComponentClientParams['cookieOptions']; + +const optionalCookieOptions: CookieOptions = isDevelopment + ? undefined + : { + domain: '.digger.dev', + secure: false, + path: '/', + sameSite: 'lax', + }; // apologies for the name, but it's the best I could come up with as // the util exported from @supabase/auth-helpers-nextjs is called @@ -12,4 +28,5 @@ export const supabaseUserClientComponentClient = fetch, }, }, + cookieOptions: optionalCookieOptions, });