IA-933:feat: Two-Factor Authentication (2FA) - Frontend
What
Implemented the complete 2FA flow on the frontend, including login redirection, OTP verification page, and 2FA settings management.
Changes
userEndpoints.ts:
- Added
twoFactorStatus,twoFactorSetup,twoFactorVerifyendpoints
userStore.ts:
- Added
fetchTwoFactorStatus— fetch current 2FA status from API - Added
saveTwoFactorSetup— enable/disable 2FA and set method
auth/types.ts:
- Added
signIn,verifyTwoFactor,pendingTwoFactor,pendingEmailtoAuthContextValue
AuthProvider.tsx:
- Added
signIn— handles login with 2FA support - Added
verifyTwoFactor— verifies OTP and sets session - Added
pendingTwoFactorandpendingEmailstate
JwtSignInView.tsx:
- Replaced
signInWithPasswordwithsignInfrom context - Added redirection to
/auth/two-factor-verifywhentwoFactorRequired: true
SecurityView.tsx:
- Connected toggle and save button to real API (
fetchTwoFactorStatus,saveTwoFactorSetup) - Save button now always visible regardless of toggle state
paths.ts:
- Added
twoFactorVerifyroute underauth
New page auth/two-factor-verify/page.tsx:
- OTP input with 6 fields
- Paste support
- Calls
verifyTwoFactorand redirects to dashboard on success
Flow
- User submits login form
-
signIncalls backend → iftwoFactorRequired: true, email stored insessionStorage - User redirected to
/auth/two-factor-verify - User enters OTP →
verifyTwoFactorcalled → JWT stored → redirected to dashboard
Notes
-
pendingEmailstored insessionStorageto persist across page navigation - 2FA can be enabled/disabled from Security settings page
- OTP page accessible without authentication (GuestGuard)