From dfbe1573b9e40474aff23e32444dfd3b2fcfe4b3 Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Wed, 18 Jun 2025 18:44:38 +0200 Subject: [PATCH] feat: Pass the `auth_id` and `token` params to the email confirmation URL (#36327) * Pass the auth_id and token params when the user is signed up. * Try to fix the vercel build. * Move the code in function to avoid SSR errors. --------- Co-authored-by: Wen Bo Xie <5532241+w3b6x9@users.noreply.github.com> --- .../interfaces/SignIn/SignUpForm.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/studio/components/interfaces/SignIn/SignUpForm.tsx b/apps/studio/components/interfaces/SignIn/SignUpForm.tsx index 8f427e9f78d66..52a117d6e6be5 100644 --- a/apps/studio/components/interfaces/SignIn/SignUpForm.tsx +++ b/apps/studio/components/interfaces/SignIn/SignUpForm.tsx @@ -1,5 +1,6 @@ import HCaptcha from '@hcaptcha/react-hcaptcha' import { CheckCircle, Eye, EyeOff } from 'lucide-react' +import { parseAsString, useQueryStates } from 'nuqs' import { useRef, useState } from 'react' import { toast } from 'sonner' import * as yup from 'yup' @@ -28,6 +29,11 @@ const SignUpForm = () => { const [passwordHidden, setPasswordHidden] = useState(true) const [captchaToken, setCaptchaToken] = useState(null) + const [searchParams] = useQueryStates({ + auth_id: parseAsString.withDefault(''), + token: parseAsString.withDefault(''), + }) + const { mutate: signup, isLoading: isSigningUp } = useSignUpMutation({ onSuccess: () => { toast.success(`Signed up successfully!`) @@ -47,15 +53,21 @@ const SignUpForm = () => { token = captchaResponse?.response ?? null } + const isInsideOAuthFlow = !!searchParams.auth_id + const redirectUrlBase = `${ + process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview' + ? location.origin + : process.env.NEXT_PUBLIC_SITE_URL + }${BASE_PATH}` + const redirectTo = isInsideOAuthFlow + ? `${redirectUrlBase}/authorize?auth_id=${searchParams.auth_id}${searchParams.token && `&token=${searchParams.token}`}` + : `${redirectUrlBase}/sign-in` + signup({ email, password, hcaptchaToken: token ?? null, - redirectTo: `${ - process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview' - ? location.origin - : process.env.NEXT_PUBLIC_SITE_URL - }${BASE_PATH}/sign-in`, + redirectTo, }) }