File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { EmailOtpType } from "@supabase/supabase-js" ;
2+ import { redirect , type RequestHandler } from "@sveltejs/kit" ;
3+
4+ export const GET : RequestHandler = async ( { url, locals : { supabase } } ) => {
5+ const token_hash = url . searchParams . get ( "token_hash" ) ;
6+ const type = url . searchParams . get ( "type" ) as EmailOtpType | null ;
7+ const next = url . searchParams . get ( "next" ) ?? "/" ;
8+
9+ /**
10+ * Clean up the redirect URL by deleting the Auth flow parameters.
11+ *
12+ * `next` is preserved for now, because it's needed in the error case.
13+ */
14+ const redirectTo = new URL ( url ) ;
15+ redirectTo . pathname = next ;
16+ redirectTo . searchParams . delete ( "token_hash" ) ;
17+ redirectTo . searchParams . delete ( "type" ) ;
18+
19+ if ( token_hash && type ) {
20+ const { error } = await supabase . auth . verifyOtp ( { type, token_hash } ) ;
21+ if ( ! error ) {
22+ redirectTo . searchParams . delete ( "next" ) ;
23+ redirect ( 303 , redirectTo ) ;
24+ }
25+ }
26+
27+ redirectTo . pathname = "/auth/error" ;
28+ redirect ( 303 , redirectTo ) ;
29+ } ;
Original file line number Diff line number Diff line change 1+ <p >Login error</p >
2+
You can’t perform that action at this time.
0 commit comments