Spaces:
Sleeping
Sleeping
File size: 894 Bytes
e3f2df1 ae80634 e3f2df1 ae80634 e3f2df1 f36152d e3f2df1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import { createClient } from "@/lib/supabase/server";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");
let next = requestUrl.searchParams.get("next") || "/dashboard-pages/dashboard";
const origin = requestUrl.origin;
// Prevent open redirect
if (next && !next.startsWith("/")) {
next = "/dashboard-pages/dashboard";
}
if (code) {
const supabase = await createClient();
const { error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) {
return NextResponse.redirect(`${origin}${next}`);
}
}
// If code exchange failed, try hash-based recovery (password reset flow)
// Supabase sends recovery tokens as hash fragments which the client handles
return NextResponse.redirect(`${origin}${next}`);
}
|