Skip to content

Commit

Permalink
<testing> client cookie changes
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Jul 19, 2024
1 parent c3d294f commit 8a94aeb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
23 changes: 18 additions & 5 deletions src/supabase-clients/user/createSupabaseUserRouteHandlerClient.ts
Original file line number Diff line number Diff line change
@@ -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<typeof createRouteHandlerClient>[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 = () =>
Expand All @@ -9,10 +26,6 @@ export const createSupabaseUserRouteHandlerClient = () =>
cookies,
},
{
options: {
global: {
fetch,
},
},
cookieOptions: optionalCookieOptions,
},
);
27 changes: 24 additions & 3 deletions src/supabase-clients/user/createSupabaseUserServerActionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createServerActionClient>[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<Database>({
cookies,
});
createServerActionClient<Database>(
{
cookies,
},
{
cookieOptions: optionalCookieOptions,
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createServerComponentClient>[1]
>;
type CookieOptions = createServerComponentClientParams['cookieOptions'];

const optionalCookieOptions: CookieOptions = isDevelopment
? undefined
: {
domain: '.digger.dev',
secure: false,
path: '/',
sameSite: 'lax',
};

export const createSupabaseUserServerComponentClient = () =>
createServerComponentClient<Database>(
{
Expand All @@ -13,5 +29,6 @@ export const createSupabaseUserServerComponentClient = () =>
fetch,
},
},
cookieOptions: optionalCookieOptions,
},
);
19 changes: 18 additions & 1 deletion src/supabase-clients/user/supabaseUserClientComponentClient.ts
Original file line number Diff line number Diff line change
@@ -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<typeof createClientComponentClient>[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
Expand All @@ -12,4 +28,5 @@ export const supabaseUserClientComponentClient =
fetch,
},
},
cookieOptions: optionalCookieOptions,
});

0 comments on commit 8a94aeb

Please sign in to comment.