Updated the default redirect URL in the auth confirmation route using the home URL from paths.config. Also renamed and enhanced 'CaptchaTokenSetter' to include optional Turnstile properties. This enhancement allows customization of the captcha based on the provided options while maintaining backwards compatibility.
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
import { type EmailOtpType } from '@supabase/supabase-js';
|
|
|
|
import { getSupabaseRouteHandlerClient } from '@kit/supabase/route-handler-client';
|
|
|
|
import pathsConfig from '~/config/paths.config';
|
|
|
|
const defaultNextUrl = pathsConfig.app.home;
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
const token_hash = searchParams.get('token_hash');
|
|
const type = searchParams.get('type') as EmailOtpType | null;
|
|
const next = searchParams.get('next') ?? defaultNextUrl;
|
|
const redirectTo = request.nextUrl.clone();
|
|
|
|
redirectTo.pathname = next;
|
|
|
|
if (token_hash && type) {
|
|
const supabase = getSupabaseRouteHandlerClient();
|
|
|
|
const { error } = await supabase.auth.verifyOtp({
|
|
type,
|
|
token_hash,
|
|
});
|
|
|
|
if (!error) {
|
|
return NextResponse.redirect(redirectTo);
|
|
}
|
|
}
|
|
|
|
// return the user to an error page with some instructions
|
|
redirectTo.pathname = '/auth/callback/error';
|
|
|
|
return NextResponse.redirect(redirectTo);
|
|
}
|