Update auth confirmation route and enhance captcha functionality

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.
This commit is contained in:
giancarlo
2024-04-27 15:19:33 +07:00
parent 07deb28e12
commit ec59d02fb0
4 changed files with 34 additions and 19 deletions

View File

@@ -4,11 +4,15 @@ 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') ?? '/';
const next = searchParams.get('next') ?? defaultNextUrl;
const redirectTo = request.nextUrl.clone();
redirectTo.pathname = next;

View File

@@ -0,0 +1,28 @@
'use client';
import { useContext } from 'react';
import { Turnstile, TurnstileProps } from '@marsidev/react-turnstile';
import { Captcha } from './captcha-provider';
export function CaptchaTokenSetter(props: {
siteKey: string | undefined;
options?: TurnstileProps;
}) {
const { setToken } = useContext(Captcha);
if (!props.siteKey) {
return null;
}
const options = props.options ?? {
options: {
size: 'invisible',
},
};
return (
<Turnstile siteKey={props.siteKey} onSuccess={setToken} {...options} />
);
}

View File

@@ -1,17 +0,0 @@
'use client';
import { useContext } from 'react';
import { Turnstile } from '@marsidev/react-turnstile';
import { Captcha } from './captcha-provider';
export function CaptchaTokenSetter(props: { siteKey: string | undefined }) {
const { setToken } = useContext(Captcha);
if (!props.siteKey) {
return null;
}
return <Turnstile siteKey={props.siteKey} onSuccess={setToken} />;
}

View File

@@ -1,3 +1,3 @@
export * from './captchaTokenSetter';
export * from './captcha-token-setter';
export * from './use-captcha-token';
export * from './captcha-provider';