Skip to content

User Authentication ## Business Purpose Provide a secure login, registration, and password recovery system for users to access the platform. ## Current Behaviors - Login: Users submit email and password; server validates credentials and returns a JWT token stored in the client cache login.tsx:65.

  • Signup: New users register with name, email, and password; server creates a user via private API and redirects to login signup.tsx:74.
  • Password Recovery: Users request a password reset email; a recovery token is sent and validated recover-password.tsx:60.
  • Token Management: The useAuth hook manages login state, token storage, and logout by clearing cached queries useAuth.ts:30.
  • Backend Security: Passwords are hashed using bcrypt (upgraded to Argon2) and tokens are created with expiration security.py:22. ## Technical Implementation - Frontend Routes: Login form at login.tsx:37-65, signup form at signup.tsx:35-74, password recovery at recover-password.tsx:35-68, reset password at reset-password.tsx:42-95.
  • API Calls: SDK functions loginAccessToken, registerUser, recoverPassword, resetPassword (sdk.gen.ts:128-165, 356-375).
  • State Management: useAuth hook uses React Query's queryClient to store/clear token useAuth.ts:14.
  • Backend Endpoints: /api/v1/login/access-token, /api/v1/users/register, /api/v1/password/recovery, /api/v1/password/reset (routes/login.py, routes/users.py:147).
  • Security Utilities: create_access_token with expires_delta, verify_password, get_password_hash security.py:22.
  • Test Fixtures: superuser_token_headers and normal_user_token_headers created in conftest.py conftest.py:34. ## Definition of Done - Login with valid credentials returns a 200 response and sets a token in the client cache login.spec.ts:26.
  • Registration creates a new user and shows a success toast sign-up.spec.ts:36.
  • Password recovery email is sent via MailCatcher and token is stored reset-password.spec.ts:30.
  • Invalid credentials return a 4xx error and display an error message login.spec.ts:53.
  • The token expiration redirects the user to login (covered by E2E test for session expiry).