From ec59d02fb0eb9dc060bd1f456177b298cdc9c7e4 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Sat, 27 Apr 2024 15:19:33 +0700 Subject: [PATCH] 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. --- apps/web/app/auth/confirm/route.ts | 6 +++- .../captcha/client/captcha-token-setter.tsx | 28 +++++++++++++++++++ .../src/captcha/client/captchaTokenSetter.tsx | 17 ----------- .../features/auth/src/captcha/client/index.ts | 2 +- 4 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 packages/features/auth/src/captcha/client/captcha-token-setter.tsx delete mode 100644 packages/features/auth/src/captcha/client/captchaTokenSetter.tsx diff --git a/apps/web/app/auth/confirm/route.ts b/apps/web/app/auth/confirm/route.ts index 534f71d15..9f22193cf 100644 --- a/apps/web/app/auth/confirm/route.ts +++ b/apps/web/app/auth/confirm/route.ts @@ -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; diff --git a/packages/features/auth/src/captcha/client/captcha-token-setter.tsx b/packages/features/auth/src/captcha/client/captcha-token-setter.tsx new file mode 100644 index 000000000..bfb8f51de --- /dev/null +++ b/packages/features/auth/src/captcha/client/captcha-token-setter.tsx @@ -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 ( + + ); +} diff --git a/packages/features/auth/src/captcha/client/captchaTokenSetter.tsx b/packages/features/auth/src/captcha/client/captchaTokenSetter.tsx deleted file mode 100644 index 59068be39..000000000 --- a/packages/features/auth/src/captcha/client/captchaTokenSetter.tsx +++ /dev/null @@ -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 ; -} diff --git a/packages/features/auth/src/captcha/client/index.ts b/packages/features/auth/src/captcha/client/index.ts index 14f70c5f0..27762c227 100644 --- a/packages/features/auth/src/captcha/client/index.ts +++ b/packages/features/auth/src/captcha/client/index.ts @@ -1,3 +1,3 @@ -export * from './captchaTokenSetter'; +export * from './captcha-token-setter'; export * from './use-captcha-token'; export * from './captcha-provider';