Skip to content

Commit 503268e

Browse files
authored
fix(email): manual OTP instead of better-auth (#921)
* fix(email): manual OTP instead of better-auth * lint
1 parent 9a4de1f commit 503268e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

apps/sim/app/(auth)/signup/signup-form.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { Input } from '@/components/ui/input'
99
import { Label } from '@/components/ui/label'
1010
import { client } from '@/lib/auth-client'
1111
import { quickValidateEmail } from '@/lib/email/validation'
12+
import { createLogger } from '@/lib/logs/console/logger'
1213
import { cn } from '@/lib/utils'
1314
import { SocialLoginButtons } from '@/app/(auth)/components/social-login-buttons'
1415

16+
const logger = createLogger('SignupForm')
17+
1518
const PASSWORD_VALIDATIONS = {
1619
minLength: { regex: /.{8,}/, message: 'Password must be at least 8 characters long.' },
1720
uppercase: {
@@ -281,7 +284,7 @@ function SignupFormContent({
281284
},
282285
{
283286
onError: (ctx) => {
284-
console.error('Signup error:', ctx.error)
287+
logger.error('Signup error:', ctx.error)
285288
const errorMessage: string[] = ['Failed to create account']
286289

287290
if (ctx.error.code?.includes('USER_ALREADY_EXISTS')) {
@@ -343,10 +346,21 @@ function SignupFormContent({
343346
}
344347
}
345348

349+
// Send verification OTP manually
350+
try {
351+
await client.emailOtp.sendVerificationOtp({
352+
email: emailValue,
353+
type: 'email-verification',
354+
})
355+
} catch (otpError) {
356+
logger.error('Failed to send OTP:', otpError)
357+
// Continue anyway - user can use resend button
358+
}
359+
346360
// Always redirect to verification for new signups
347361
router.push('/verify?fromSignup=true')
348362
} catch (error) {
349-
console.error('Signup error:', error)
363+
logger.error('Signup error:', error)
350364
setIsLoading(false)
351365
}
352366
}

apps/sim/lib/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const auth = betterAuth({
157157
emailAndPassword: {
158158
enabled: true,
159159
requireEmailVerification: false,
160-
sendVerificationOnSignUp: true,
160+
sendVerificationOnSignUp: false,
161161
throwOnMissingCredentials: true,
162162
throwOnInvalidCredentials: true,
163163
sendResetPassword: async ({ user, url, token }, request) => {
@@ -284,7 +284,7 @@ export const auth = betterAuth({
284284
throw error
285285
}
286286
},
287-
sendVerificationOnSignUp: true,
287+
sendVerificationOnSignUp: false,
288288
otpLength: 6, // Explicitly set the OTP length
289289
expiresIn: 15 * 60, // 15 minutes in seconds
290290
}),

0 commit comments

Comments
 (0)