Skip to content

Commit

Permalink
allez
Browse files Browse the repository at this point in the history
  • Loading branch information
farnoux committed Feb 10, 2025
1 parent 7df01f8 commit cd8c74f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
28 changes: 28 additions & 0 deletions packages/api/src/utils/supabase/server-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,31 @@ export async function createClient() {
}
);
}

export async function createClientWithOldCookie() {
const cookieStore = await cookies();

return createServerClient<Database>(
ENV.supabase_url as string,
ENV.supabase_anon_key as string,
{
// cookieOptions: getCookieOptions(),
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
);
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
);
}
12 changes: 9 additions & 3 deletions packages/auth/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createClient } from '@/api/utils/supabase/server-client';
import { createClientWithOldCookie } from '@/api/utils/supabase/server-client';
import { redirect } from 'next/navigation';
import { LoginPageClient } from './page.client';

/**
Expand All @@ -21,8 +22,13 @@ export default async function LoginPage({
const { view, email, otp, redirect_to } = await searchParams;

// Log out to clear old auth cookie
const supabase = await createClient();
await supabase.auth.signOut();
const supabase = await createClientWithOldCookie();
const { data: user } = await supabase.auth.getUser();

if (user) {
await supabase.auth.signOut();
redirect('/login');
}

return (
<LoginPageClient
Expand Down

0 comments on commit cd8c74f

Please sign in to comment.