2.6 KiB
2.6 KiB
Auth Frontend
The frontend module implements authentication screens, session provider, current-user loading, and route guards.
Source: apps/admin/src/core/Auth/
Directory Structure
Auth/
config/ Routes, messages, translations.
data/
api/ Raw auth/profile API calls and DTOs.
mappers/ Current-user DTO mapping.
stores/ Local token storage helpers.
entities/ Auth and user types.
pages/ Sign-in page.
providers/ AuthProvider and context.
view/
forms/ Sign-in form.
layouts/ Auth layouts.
widgets/ Auth guard.
Routes
Frontend route config:
config/routing.tsx
Mounted module path:
/auth/*
| Route | Page | Purpose |
|---|---|---|
/auth/signin |
SignInPage |
Admin sign-in screen. |
The index route redirects to signin.
AuthProvider
Provider file:
providers/AuthProvider/AuthProvider.tsx
Exposes:
auth;
user;
loading;
login(email, password);
logout();
verify();
getUser();
updateUser(payload);
saveAuth(auth);
setUser(user);
Important behavior:
loginstores the access token, then loads the current user.verifyreloads current user when a token exists.logoutcalls the backend, clears auth state, and clears React Query cache.updateUsercalls/admin/update-profileand updates current user state.
API Boundary
Raw API calls:
data/api/api.ts
data/api/dto.ts
| Method | Backend Route | Purpose |
|---|---|---|
login |
POST /auth/login |
Create bearer token. |
logout |
POST /auth/logout |
Invalidate current token. |
getUser |
GET /auth/user |
Load current user and permissions. |
updateUser |
PUT /admin/update-profile |
Update current admin profile. |
Current-user DTO mapping:
data/mappers/userMapper.ts
Token Storage
Token persistence helpers live in:
data/stores/localStorage.ts
Keep token storage behind these helpers so storage format changes stay local.
Route Guard
Auth guard widget:
view/widgets/AuthGuardWidget.tsx
Use this widget to protect authenticated app routes. It coordinates auth loading and redirects unauthenticated users to auth routes.
Translations
Translations are module-local:
config/messages.ts
config/translation/en.json
config/translation/uk.json
Use only AUTH.* keys inside this module.