Skip to content

Commit

Permalink
confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
craigkai committed Oct 7, 2024
1 parent 2adcb07 commit 084b507
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
currentUser = await supabase.auth.getUser();
}
supabase.auth.onAuthStateChange((event) => {
console.log(event);
supabase.auth.onAuthStateChange(() => {
getCurrentUser();
});
</script>
Expand Down
1 change: 0 additions & 1 deletion src/routes/auth/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
$effect(() => {
[$signupMessages, $signInMessages, $resetPasswordMessages].forEach((message) => {
console.log(message);
if (message) {
toast.success(message);
}
Expand Down
4 changes: 0 additions & 4 deletions src/routes/auth/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
};
32 changes: 32 additions & 0 deletions src/routes/auth/confirm/+server.ts
Original file line number Diff line number Diff line change
@@ -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);
};
1 change: 1 addition & 0 deletions src/routes/auth/error/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Login error</p>

0 comments on commit 084b507

Please sign in to comment.