mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 23:17:59 -05:00
fix(errors): fix error handling for signup/signin
This commit is contained in:
@@ -257,26 +257,22 @@ function SignupFormContent({
|
||||
return
|
||||
}
|
||||
|
||||
// Send verification OTP in Prod
|
||||
try {
|
||||
await client.emailOtp.sendVerificationOtp({
|
||||
email: emailValue,
|
||||
type: 'email-verification',
|
||||
})
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
sessionStorage.setItem('verificationEmail', emailValue)
|
||||
localStorage.setItem('has_logged_in_before', 'true')
|
||||
document.cookie = 'has_logged_in_before=true; path=/; max-age=31536000; SameSite=Lax' // 1 year expiry
|
||||
}
|
||||
|
||||
router.push('/verify')
|
||||
} catch (error) {
|
||||
console.error('Failed to send verification code:', error)
|
||||
setPasswordErrors(['Account created but failed to send verification code.'])
|
||||
setShowValidationError(true)
|
||||
router.push('/login')
|
||||
} catch (err) {
|
||||
console.error('Failed to send verification OTP:', err)
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
sessionStorage.setItem('verificationEmail', emailValue)
|
||||
localStorage.setItem('has_logged_in_before', 'true')
|
||||
document.cookie = 'has_logged_in_before=true; path=/; max-age=31536000; SameSite=Lax' // 1 year expiry
|
||||
}
|
||||
|
||||
router.push('/verify?fromSignup=true')
|
||||
} catch (error) {
|
||||
console.error('Signup error:', error)
|
||||
setIsLoading(false)
|
||||
|
||||
@@ -212,13 +212,23 @@ export function useVerification({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!isProduction || !hasResendKey) {
|
||||
setIsVerified(true)
|
||||
const timeoutId = setTimeout(() => {
|
||||
router.push('/w')
|
||||
}, 1000)
|
||||
if (typeof window !== 'undefined') {
|
||||
if (!isProduction || !hasResendKey) {
|
||||
const storedEmail = sessionStorage.getItem('verificationEmail')
|
||||
logger.info('Auto-verifying user', { email: storedEmail })
|
||||
}
|
||||
|
||||
return () => clearTimeout(timeoutId)
|
||||
const isDevOrDocker = !isProduction || process.env.DOCKER_BUILD === 'true'
|
||||
|
||||
// Auto-verify and redirect in development/docker environments
|
||||
if (isDevOrDocker || !hasResendKey) {
|
||||
setIsVerified(true)
|
||||
const timeoutId = setTimeout(() => {
|
||||
router.push('/w')
|
||||
}, 1000)
|
||||
|
||||
return () => clearTimeout(timeoutId)
|
||||
}
|
||||
}
|
||||
}, [isProduction, hasResendKey, router])
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import { env } from './env'
|
||||
const logger = createLogger('Auth')
|
||||
|
||||
const isProd = env.NODE_ENV === 'production'
|
||||
const isDevOrDocker = env.NODE_ENV === 'development' || env.DOCKER_BUILD
|
||||
|
||||
// Only initialize Stripe if the key is provided
|
||||
// This allows local development without a Stripe account
|
||||
@@ -205,9 +204,9 @@ export const auth = betterAuth({
|
||||
throw error
|
||||
}
|
||||
},
|
||||
sendVerificationOnSignUp: isProd,
|
||||
otpLength: 6,
|
||||
expiresIn: 15 * 60,
|
||||
sendVerificationOnSignUp: false,
|
||||
otpLength: 6, // Explicitly set the OTP length
|
||||
expiresIn: 15 * 60, // 15 minutes in seconds
|
||||
}),
|
||||
genericOAuth({
|
||||
config: [
|
||||
|
||||
Reference in New Issue
Block a user