Skip to content

Commit c29d95e

Browse files
Merge pull request #63 from gonzo-engineering/restore-initial-auth-check-endpoint
2 parents e5bd19f + 8bd4685 commit c29d95e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>Login error</p>
2+

0 commit comments

Comments
 (0)