src/contexts/JWTContext.tsx implements authentication for the SPA. It wraps the app in App.tsx as JWTProvider and is consumed via hooks/useAuth().

State shape — AuthProps

Reducer actions

Token helpers

verifyToken(token) — decodes JWT with jwt-decode, checks exp against current time. setSession(token) — writes serviceToken to localStorage and sets axios Authorization: Bearer header. Clears both on logout.

Boot sequence

On mount:
  1. Read localStorage.serviceToken
  2. If valid → GET /user/verifyToken
  3. Dispatch LOGIN with user payload
  4. getSocket(user._id) for Socket.IO
  5. If invalid → dispatch LOGOUT with isInitialized: true
Shows <Loader /> until initialized.

login(email, password, isForceLogin?)

  • Stores res.data.data.loginToken
  • Updates context and connects socket
  • Throws error.response.data on failure (used for MFA / force-login UI)
When MFA is enabled, password field carries the 6-digit TOTP instead.

logout()

On success: clears session, disconnectSocket(), hard redirect to /login.

Profile methods

Context value

register and resetPassword are legacy/stub implementations.