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:
@@ -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;
|
||||
|
||||
@@ -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} />
|
||||
);
|
||||
}
|
||||
@@ -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} />;
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './captchaTokenSetter';
|
||||
export * from './captcha-token-setter';
|
||||
export * from './use-captcha-token';
|
||||
export * from './captcha-provider';
|
||||
|
||||
Reference in New Issue
Block a user