From 503268ebcdf2b204ea3774389c4f52deb806bf10 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 8 Aug 2025 18:49:54 -0700 Subject: [PATCH] fix(email): manual OTP instead of better-auth (#921) * fix(email): manual OTP instead of better-auth * lint --- apps/sim/app/(auth)/signup/signup-form.tsx | 18 ++++++++++++++++-- apps/sim/lib/auth.ts | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/sim/app/(auth)/signup/signup-form.tsx b/apps/sim/app/(auth)/signup/signup-form.tsx index ba544ca84..287c62bf7 100644 --- a/apps/sim/app/(auth)/signup/signup-form.tsx +++ b/apps/sim/app/(auth)/signup/signup-form.tsx @@ -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: { @@ -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')) { @@ -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 + } + // 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) } } diff --git a/apps/sim/lib/auth.ts b/apps/sim/lib/auth.ts index 2c0005185..e3ef7354d 100644 --- a/apps/sim/lib/auth.ts +++ b/apps/sim/lib/auth.ts @@ -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) => { @@ -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 }),