Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions apps/studio/components/interfaces/SignIn/SignUpForm.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -28,6 +29,11 @@ const SignUpForm = () => {
const [passwordHidden, setPasswordHidden] = useState(true)
const [captchaToken, setCaptchaToken] = useState<string | null>(null)

const [searchParams] = useQueryStates({
auth_id: parseAsString.withDefault(''),
token: parseAsString.withDefault(''),
})

const { mutate: signup, isLoading: isSigningUp } = useSignUpMutation({
onSuccess: () => {
toast.success(`Signed up successfully!`)
Expand All @@ -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,
})
}

Expand Down
Loading