diff --git a/src/components/Header.svelte b/src/components/Header.svelte index 9977dec..8010262 100644 --- a/src/components/Header.svelte +++ b/src/components/Header.svelte @@ -16,8 +16,7 @@ currentUser = await supabase.auth.getUser(); } - supabase.auth.onAuthStateChange((event) => { - console.log(event); + supabase.auth.onAuthStateChange(() => { getCurrentUser(); }); diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index 21e31b7..4a386ec 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -56,7 +56,6 @@ $effect(() => { [$signupMessages, $signInMessages, $resetPasswordMessages].forEach((message) => { - console.log(message); if (message) { toast.success(message); } diff --git a/src/routes/auth/+page.ts b/src/routes/auth/+page.ts index b6d2db9..5b63e3d 100644 --- a/src/routes/auth/+page.ts +++ b/src/routes/auth/+page.ts @@ -8,9 +8,5 @@ export const load: PageLoad = async ({ url }) => { redirect(303, '/auth/recovery'); } - if (url.searchParams.get('type') === 'signup') { - redirect(303, '/protected-routes/dashboard'); - } - return {}; }; diff --git a/src/routes/auth/confirm/+server.ts b/src/routes/auth/confirm/+server.ts new file mode 100644 index 0000000..08d8b42 --- /dev/null +++ b/src/routes/auth/confirm/+server.ts @@ -0,0 +1,32 @@ +// src/routes/auth/confirm/+server.ts +import type { EmailOtpType } from '@supabase/supabase-js'; +import { redirect } from '@sveltejs/kit'; + +import type { RequestHandler } from './$types'; + +export const GET: RequestHandler = async ({ url, locals: { supabase } }) => { + const token_hash = url.searchParams.get('token_hash'); + const type = url.searchParams.get('type') as EmailOtpType | null; + const next = url.searchParams.get('next') ?? '/account'; + + /** + * Clean up the redirect URL by deleting the Auth flow parameters. + * + * `next` is preserved for now, because it's needed in the error case. + */ + const redirectTo = new URL(url); + redirectTo.pathname = next; + redirectTo.searchParams.delete('token_hash'); + redirectTo.searchParams.delete('type'); + + if (token_hash && type) { + const { error } = await supabase.auth.verifyOtp({ type, token_hash }); + if (!error) { + redirectTo.searchParams.delete('next'); + redirect(303, redirectTo); + } + } + + redirectTo.pathname = '/auth/error'; + redirect(303, redirectTo); +}; diff --git a/src/routes/auth/error/+page.svelte b/src/routes/auth/error/+page.svelte new file mode 100644 index 0000000..5e995de --- /dev/null +++ b/src/routes/auth/error/+page.svelte @@ -0,0 +1 @@ +
Login error