From f3fcc28f8940d4763bd362217c824e78adfdb054 Mon Sep 17 00:00:00 2001 From: Waleed Date: Wed, 21 Jan 2026 18:34:49 -0800 Subject: [PATCH] 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 --- apps/sim/app/(auth)/login/login-form.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/sim/app/(auth)/login/login-form.tsx b/apps/sim/app/(auth)/login/login-form.tsx index a259a036f..c58b102bc 100644 --- a/apps/sim/app/(auth)/login/login-form.tsx +++ b/apps/sim/app/(auth)/login/login-form.tsx @@ -182,6 +182,13 @@ export default function LoginPage({ e.preventDefault() setIsLoading(true) + const redirectToVerify = (emailToVerify: string) => { + if (typeof window !== 'undefined') { + sessionStorage.setItem('verificationEmail', emailToVerify) + } + router.push('/verify') + } + const formData = new FormData(e.currentTarget) const emailRaw = formData.get('email') as string const email = emailRaw.trim().toLowerCase() @@ -213,9 +220,9 @@ export default function LoginPage({ onError: (ctx) => { logger.error('Login error:', ctx.error) - // EMAIL_NOT_VERIFIED is handled by the catch block which redirects to /verify if (ctx.error.code?.includes('EMAIL_NOT_VERIFIED')) { errorHandled = true + redirectToVerify(email) return } @@ -283,10 +290,7 @@ export default function LoginPage({ router.push(safeCallbackUrl) } catch (err: any) { if (err.message?.includes('not verified') || err.code?.includes('EMAIL_NOT_VERIFIED')) { - if (typeof window !== 'undefined') { - sessionStorage.setItem('verificationEmail', email) - } - router.push('/verify') + redirectToVerify(email) return }