23 lines
746 B
TypeScript
23 lines
746 B
TypeScript
import { createClient } from "@/utils/supabase/server";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function GET(request: Request) {
|
|
const { searchParams, origin } = new URL(request.url);
|
|
|
|
const code = searchParams.get("code");
|
|
// If the user clicked the email confirmation link, there may be a "next" param
|
|
const next = searchParams.get("next") ?? "/profile";
|
|
|
|
if (code) {
|
|
const supabase = await createClient();
|
|
const { error } = await supabase.auth.exchangeCodeForSession(code);
|
|
|
|
if (!error) {
|
|
return NextResponse.redirect(`${origin}${next}`);
|
|
}
|
|
}
|
|
|
|
// If no code or exchange failed, redirect to login with an error
|
|
return NextResponse.redirect(`${origin}/login?error=confirmation-failed`);
|
|
}
|