Use setSession from hash tokens before exchange

cgen-f249e8cfc26646d58d72275d0e2d493b
This commit is contained in:
Builder.io 2025-10-18 01:32:12 +00:00
parent 8fc012ee9c
commit b011b673a4

View file

@ -46,11 +46,21 @@ export default function ResetPassword() {
setLinkError(urlErrorDesc || "Reset link is invalid or has expired.");
return;
}
try {
await supabase.auth.exchangeCodeForSession(window.location.href);
} catch (e: any) {
setLinkError("Reset link is invalid or has expired.");
return;
const access_token = params.get("access_token");
const refresh_token = params.get("refresh_token");
if (access_token && refresh_token) {
const { error: setErr } = await supabase.auth.setSession({ access_token, refresh_token });
if (setErr) {
setLinkError("Reset link is invalid or has expired.");
return;
}
} else {
try {
await supabase.auth.exchangeCodeForSession(window.location.href);
} catch (e: any) {
setLinkError("Reset link is invalid or has expired.");
return;
}
}
const { data } = await supabase.auth.getSession();
if (!data?.session) {