Skip to content

IA-933:feat: Two-Factor Authentication (2FA) - Frontend

khadija.elbachouri a demandé de fusionner feature/IA-933 vers develop

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, twoFactorVerify endpoints

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, pendingEmail to AuthContextValue

AuthProvider.tsx:

  • Added signIn — handles login with 2FA support
  • Added verifyTwoFactor — verifies OTP and sets session
  • Added pendingTwoFactor and pendingEmail state

JwtSignInView.tsx:

  • Replaced signInWithPassword with signIn from context
  • Added redirection to /auth/two-factor-verify when twoFactorRequired: 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 twoFactorVerify route under auth

New page auth/two-factor-verify/page.tsx:

  • OTP input with 6 fields
  • Paste support
  • Calls verifyTwoFactor and redirects to dashboard on success

Flow

  1. User submits login form
  2. signIn calls backend → if twoFactorRequired: true, email stored in sessionStorage
  3. User redirected to /auth/two-factor-verify
  4. User enters OTP → verifyTwoFactor called → JWT stored → redirected to dashboard

Notes

  • pendingEmail stored in sessionStorage to persist across page navigation
  • 2FA can be enabled/disabled from Security settings page
  • OTP page accessible without authentication (GuestGuard)

Rapports de requête de fusion