From 745bebb06738f52fb82fad30796f280e24973c55 Mon Sep 17 00:00:00 2001 From: Ignacio Dobronich Date: Mon, 21 Jul 2025 11:28:54 -0300 Subject: [PATCH] chore: support redirect query params on signup (#37272) --- .../interfaces/SignIn/SignUpForm.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/studio/components/interfaces/SignIn/SignUpForm.tsx b/apps/studio/components/interfaces/SignIn/SignUpForm.tsx index 52a117d6e6be5..bd6a7772c41c1 100644 --- a/apps/studio/components/interfaces/SignIn/SignUpForm.tsx +++ b/apps/studio/components/interfaces/SignIn/SignUpForm.tsx @@ -4,10 +4,12 @@ import { parseAsString, useQueryStates } from 'nuqs' import { useRef, useState } from 'react' import { toast } from 'sonner' import * as yup from 'yup' +import { useRouter } from 'next/router' import { useSignUpMutation } from 'data/misc/signup-mutation' import { BASE_PATH } from 'lib/constants' import { passwordSchema } from 'lib/schemas' +import { buildPathWithParams } from 'lib/gotrue' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, @@ -28,6 +30,7 @@ const SignUpForm = () => { const [isSubmitted, setIsSubmitted] = useState(false) const [passwordHidden, setPasswordHidden] = useState(true) const [captchaToken, setCaptchaToken] = useState(null) + const router = useRouter() const [searchParams] = useQueryStates({ auth_id: parseAsString.withDefault(''), @@ -59,9 +62,19 @@ const SignUpForm = () => { ? 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` + + let redirectTo: string + + if (isInsideOAuthFlow) { + redirectTo = `${redirectUrlBase}/authorize?auth_id=${searchParams.auth_id}${searchParams.token && `&token=${searchParams.token}`}` + } else { + // Use getRedirectToPath to handle redirect_to parameter and other query params + const { returnTo } = router.query + const basePath = returnTo || '/sign-in' + const fullPath = buildPathWithParams(basePath as string) + const fullRedirectUrl = `${redirectUrlBase}${fullPath}` + redirectTo = fullRedirectUrl + } signup({ email,