Skip to content

Commit dfbe157

Browse files
ivasilovw3b6x9
andauthored
feat: Pass the auth_id and token params to the email confirmation URL (supabase#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 <[email protected]>
1 parent f95c5e6 commit dfbe157

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import HCaptcha from '@hcaptcha/react-hcaptcha'
22
import { CheckCircle, Eye, EyeOff } from 'lucide-react'
3+
import { parseAsString, useQueryStates } from 'nuqs'
34
import { useRef, useState } from 'react'
45
import { toast } from 'sonner'
56
import * as yup from 'yup'
@@ -28,6 +29,11 @@ const SignUpForm = () => {
2829
const [passwordHidden, setPasswordHidden] = useState(true)
2930
const [captchaToken, setCaptchaToken] = useState<string | null>(null)
3031

32+
const [searchParams] = useQueryStates({
33+
auth_id: parseAsString.withDefault(''),
34+
token: parseAsString.withDefault(''),
35+
})
36+
3137
const { mutate: signup, isLoading: isSigningUp } = useSignUpMutation({
3238
onSuccess: () => {
3339
toast.success(`Signed up successfully!`)
@@ -47,15 +53,21 @@ const SignUpForm = () => {
4753
token = captchaResponse?.response ?? null
4854
}
4955

56+
const isInsideOAuthFlow = !!searchParams.auth_id
57+
const redirectUrlBase = `${
58+
process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'
59+
? location.origin
60+
: process.env.NEXT_PUBLIC_SITE_URL
61+
}${BASE_PATH}`
62+
const redirectTo = isInsideOAuthFlow
63+
? `${redirectUrlBase}/authorize?auth_id=${searchParams.auth_id}${searchParams.token && `&token=${searchParams.token}`}`
64+
: `${redirectUrlBase}/sign-in`
65+
5066
signup({
5167
email,
5268
password,
5369
hcaptchaToken: token ?? null,
54-
redirectTo: `${
55-
process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'
56-
? location.origin
57-
: process.env.NEXT_PUBLIC_SITE_URL
58-
}${BASE_PATH}/sign-in`,
70+
redirectTo,
5971
})
6072
}
6173

0 commit comments

Comments
 (0)