Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: support redirect query params on signup (#37272)

Ignacio Dobronich745bebb06738
diff --git a/apps/studio/components/interfaces/SignIn/SignUpForm.tsx b/apps/studio/components/interfaces/SignIn/SignUpForm.tsx
index 52a117d6e6b..bd6a7772c41 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<string | null>(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,