Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions apps/sim/app/(auth)/signup/signup-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { client } from '@/lib/auth-client'
import { quickValidateEmail } from '@/lib/email/validation'
import { createLogger } from '@/lib/logs/console/logger'
import { cn } from '@/lib/utils'
import { SocialLoginButtons } from '@/app/(auth)/components/social-login-buttons'

const logger = createLogger('SignupForm')

const PASSWORD_VALIDATIONS = {
minLength: { regex: /.{8,}/, message: 'Password must be at least 8 characters long.' },
uppercase: {
Expand Down Expand Up @@ -281,7 +284,7 @@ function SignupFormContent({
},
{
onError: (ctx) => {
console.error('Signup error:', ctx.error)
logger.error('Signup error:', ctx.error)
const errorMessage: string[] = ['Failed to create account']

if (ctx.error.code?.includes('USER_ALREADY_EXISTS')) {
Expand Down Expand Up @@ -343,10 +346,21 @@ function SignupFormContent({
}
}

// Send verification OTP manually
try {
await client.emailOtp.sendVerificationOtp({
email: emailValue,
type: 'email-verification',
})
} catch (otpError) {
logger.error('Failed to send OTP:', otpError)
// Continue anyway - user can use resend button
}
Comment on lines +349 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: OTP sending happens outside the signup success check. If signup fails but this code is reached, users might receive verification emails for failed accounts.

Suggested change
// Send verification OTP manually
try {
await client.emailOtp.sendVerificationOtp({
email: emailValue,
type: 'email-verification',
})
} catch (otpError) {
logger.error('Failed to send OTP:', otpError)
// Continue anyway - user can use resend button
}
// Only send OTP if signup was successful
if (response && !response.error) {
// Send verification OTP manually
try {
await client.emailOtp.sendVerificationOtp({
email: emailValue,
type: 'email-verification',
})
} catch (otpError) {
logger.error('Failed to send OTP:', otpError)
// Continue anyway - user can use resend button
}
}


// Always redirect to verification for new signups
router.push('/verify?fromSignup=true')
} catch (error) {
console.error('Signup error:', error)
logger.error('Signup error:', error)
setIsLoading(false)
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const auth = betterAuth({
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
sendVerificationOnSignUp: true,
sendVerificationOnSignUp: false,
throwOnMissingCredentials: true,
throwOnInvalidCredentials: true,
sendResetPassword: async ({ user, url, token }, request) => {
Expand Down Expand Up @@ -284,7 +284,7 @@ export const auth = betterAuth({
throw error
}
},
sendVerificationOnSignUp: true,
sendVerificationOnSignUp: false,
otpLength: 6, // Explicitly set the OTP length
expiresIn: 15 * 60, // 15 minutes in seconds
}),
Expand Down