mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix: remove duplicate verification emails sent on signup
This commit is contained in:
+12
-21
@@ -42,28 +42,19 @@ export default function LoginPage() {
|
||||
let errorMessage = 'Invalid email or password'
|
||||
|
||||
if (err.message?.includes('not verified')) {
|
||||
errorMessage =
|
||||
'Please verify your email before signing in. Would you like to resend the verification code?'
|
||||
// Redirect to verification page directly without asking for confirmation
|
||||
try {
|
||||
// Send a new verification OTP
|
||||
await client.emailOtp.sendVerificationOtp({
|
||||
email,
|
||||
type: 'email-verification',
|
||||
})
|
||||
|
||||
// Offer to send a verification code and redirect to verification page
|
||||
const resendVerification = window.confirm(
|
||||
'Your email is not verified. Would you like to resend the verification code and go to the verification page?'
|
||||
)
|
||||
|
||||
if (resendVerification) {
|
||||
try {
|
||||
// Send a new verification OTP
|
||||
await client.emailOtp.sendVerificationOtp({
|
||||
email,
|
||||
type: 'email-verification',
|
||||
})
|
||||
|
||||
// Redirect to the verify page
|
||||
router.push(`/verify?email=${encodeURIComponent(email)}`)
|
||||
return
|
||||
} catch (verifyErr) {
|
||||
errorMessage = 'Failed to send verification code. Please try again later.'
|
||||
}
|
||||
// Redirect to the verify page
|
||||
router.push(`/verify?email=${encodeURIComponent(email)}`)
|
||||
return
|
||||
} catch (verifyErr) {
|
||||
errorMessage = 'Failed to send verification code. Please try again later.'
|
||||
}
|
||||
} else if (err.message?.includes('not found')) {
|
||||
errorMessage = 'No account found with this email. Please sign up first.'
|
||||
|
||||
@@ -36,9 +36,8 @@ export default function SignupPage() {
|
||||
try {
|
||||
await client.signUp.email({ email, password, name })
|
||||
|
||||
// No need to manually send OTP as it's handled by sendVerificationOnSignUp
|
||||
// Redirect directly to the verify page instead of verify-request
|
||||
router.push(`/verify?email=${encodeURIComponent(email)}`)
|
||||
// Pass fromSignup=true to indicate we're coming from signup
|
||||
router.push(`/verify?email=${encodeURIComponent(email)}&fromSignup=true`)
|
||||
} catch (err: any) {
|
||||
let errorMessage = 'Failed to create account'
|
||||
|
||||
|
||||
+20
-16
@@ -41,23 +41,27 @@ function VerifyContent() {
|
||||
useEffect(() => {
|
||||
if (email && !isSendingInitialOtp) {
|
||||
setIsSendingInitialOtp(true)
|
||||
// Send verification OTP on initial page load
|
||||
client.emailOtp
|
||||
.sendVerificationOtp({
|
||||
email,
|
||||
type: 'email-verification',
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((error) => {
|
||||
logger.error('Failed to send initial verification code:', error)
|
||||
addNotification?.(
|
||||
'error',
|
||||
'Failed to send verification code. Please use the resend button.',
|
||||
null
|
||||
)
|
||||
})
|
||||
|
||||
// Only send verification OTP if we're coming from login page
|
||||
// Skip this if coming from signup since the OTP is already sent
|
||||
if (!searchParams.get('fromSignup')) {
|
||||
client.emailOtp
|
||||
.sendVerificationOtp({
|
||||
email,
|
||||
type: 'email-verification',
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((error) => {
|
||||
logger.error('Failed to send initial verification code:', error)
|
||||
addNotification?.(
|
||||
'error',
|
||||
'Failed to send verification code. Please use the resend button.',
|
||||
null
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [email, isSendingInitialOtp, addNotification])
|
||||
}, [email, isSendingInitialOtp, addNotification, searchParams])
|
||||
|
||||
// Enable the verify button when all 6 digits are entered
|
||||
const isOtpComplete = otp.length === 6
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export const auth = betterAuth({
|
||||
},
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
requireEmailVerification: true,
|
||||
requireEmailVerification: false,
|
||||
sendVerificationOnSignUp: false,
|
||||
throwOnMissingCredentials: true,
|
||||
throwOnInvalidCredentials: true,
|
||||
|
||||
Reference in New Issue
Block a user