Skip to content

Commit 745bebb

Browse files
authored
chore: support redirect query params on signup (supabase#37272)
1 parent 63028c6 commit 745bebb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

apps/studio/components/interfaces/SignIn/SignUpForm.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { parseAsString, useQueryStates } from 'nuqs'
44
import { useRef, useState } from 'react'
55
import { toast } from 'sonner'
66
import * as yup from 'yup'
7+
import { useRouter } from 'next/router'
78

89
import { useSignUpMutation } from 'data/misc/signup-mutation'
910
import { BASE_PATH } from 'lib/constants'
1011
import { passwordSchema } from 'lib/schemas'
12+
import { buildPathWithParams } from 'lib/gotrue'
1113
import {
1214
AlertDescription_Shadcn_,
1315
AlertTitle_Shadcn_,
@@ -28,6 +30,7 @@ const SignUpForm = () => {
2830
const [isSubmitted, setIsSubmitted] = useState(false)
2931
const [passwordHidden, setPasswordHidden] = useState(true)
3032
const [captchaToken, setCaptchaToken] = useState<string | null>(null)
33+
const router = useRouter()
3134

3235
const [searchParams] = useQueryStates({
3336
auth_id: parseAsString.withDefault(''),
@@ -59,9 +62,19 @@ const SignUpForm = () => {
5962
? location.origin
6063
: process.env.NEXT_PUBLIC_SITE_URL
6164
}${BASE_PATH}`
62-
const redirectTo = isInsideOAuthFlow
63-
? `${redirectUrlBase}/authorize?auth_id=${searchParams.auth_id}${searchParams.token && `&token=${searchParams.token}`}`
64-
: `${redirectUrlBase}/sign-in`
65+
66+
let redirectTo: string
67+
68+
if (isInsideOAuthFlow) {
69+
redirectTo = `${redirectUrlBase}/authorize?auth_id=${searchParams.auth_id}${searchParams.token && `&token=${searchParams.token}`}`
70+
} else {
71+
// Use getRedirectToPath to handle redirect_to parameter and other query params
72+
const { returnTo } = router.query
73+
const basePath = returnTo || '/sign-in'
74+
const fullPath = buildPathWithParams(basePath as string)
75+
const fullRedirectUrl = `${redirectUrlBase}${fullPath}`
76+
redirectTo = fullRedirectUrl
77+
}
6578

6679
signup({
6780
email,

0 commit comments

Comments
 (0)