Skip to content

Commit f3fcc28

Browse files
authored
fix(auth): handle EMAIL_NOT_VERIFIED in onError callback (#2932)
* fix(auth): handle EMAIL_NOT_VERIFIED in onError callback * refactor(auth): extract redirectToVerify helper to reduce duplication
1 parent 7cfdf46 commit f3fcc28

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ export default function LoginPage({
182182
e.preventDefault()
183183
setIsLoading(true)
184184

185+
const redirectToVerify = (emailToVerify: string) => {
186+
if (typeof window !== 'undefined') {
187+
sessionStorage.setItem('verificationEmail', emailToVerify)
188+
}
189+
router.push('/verify')
190+
}
191+
185192
const formData = new FormData(e.currentTarget)
186193
const emailRaw = formData.get('email') as string
187194
const email = emailRaw.trim().toLowerCase()
@@ -213,9 +220,9 @@ export default function LoginPage({
213220
onError: (ctx) => {
214221
logger.error('Login error:', ctx.error)
215222

216-
// EMAIL_NOT_VERIFIED is handled by the catch block which redirects to /verify
217223
if (ctx.error.code?.includes('EMAIL_NOT_VERIFIED')) {
218224
errorHandled = true
225+
redirectToVerify(email)
219226
return
220227
}
221228

@@ -283,10 +290,7 @@ export default function LoginPage({
283290
router.push(safeCallbackUrl)
284291
} catch (err: any) {
285292
if (err.message?.includes('not verified') || err.code?.includes('EMAIL_NOT_VERIFIED')) {
286-
if (typeof window !== 'undefined') {
287-
sessionStorage.setItem('verificationEmail', email)
288-
}
289-
router.push('/verify')
293+
redirectToVerify(email)
290294
return
291295
}
292296

0 commit comments

Comments
 (0)