TASKS-1823 WebManager module

This commit is contained in:
Igor Martyniuk
2026-08-28 08:35:58 +00:00
parent fdb2cf3837
commit c93d8c025b
654 changed files with 26232 additions and 6075 deletions
+39
View File
@@ -0,0 +1,39 @@
# Auth Module
The Auth module owns admin authentication, current-user state, token persistence, auth routes, and route guarding.
## Source Map
| Area | Path |
| --------------------- | ---------------------------------------------------- |
| Frontend module | `apps/admin/src/core/Auth/` |
| Frontend routes | `apps/admin/src/core/Auth/config/routing.tsx` |
| Frontend provider | `apps/admin/src/core/Auth/providers/AuthProvider/` |
| Frontend translations | `apps/admin/src/core/Auth/config/translation/` |
| Backend module | `apps/backend/app/base_modules/Auth/` |
| Backend admin model | `apps/backend/app/base_modules/Admin/model/admin.ts` |
| Auth config | `apps/backend/config/auth.ts` |
## Documentation
| Page | Purpose |
| ------------------------- | ------------------------------------------------------------------------------------- |
| [Frontend](./frontend.md) | AuthProvider, login page, route guard, token storage, and translations. |
| [Backend](./backend.md) | Login/logout/current-user routes, validators, token behavior, and response contracts. |
## Main Capabilities
- Sign in with admin email and password.
- Store bearer token client-side.
- Verify and load current authenticated admin.
- Expose current user, permissions, login, logout, verify, and profile update methods.
- Guard app routes until authentication is known.
- Clear React Query cache on logout.
## Ownership Rules
- Auth owns session state and current user state.
- Auth owns token persistence.
- Auth owns auth route UI and auth guard widget.
- AccountSettings may call AuthProvider `updateUser` but does not own auth state.
- Permission gates consume `AuthUser.permissions` but do not fetch auth state themselves.
+105
View File
@@ -0,0 +1,105 @@
# Auth Backend
The backend Auth module exposes token-based admin authentication routes.
Source: `apps/backend/app/base_modules/Auth/`
## Routes
| Method | Route | Controller Method | Auth Required | Purpose |
| ------ | -------------- | ----------------- | ------------- | ------------------------------------------- |
| `POST` | `/auth/login` | `login` | No | Verify credentials and create bearer token. |
| `POST` | `/auth/logout` | `logout` | Yes | Invalidate current bearer token. |
| `GET` | `/auth/user` | `user` | Yes | Return current admin and permission slugs. |
Route file:
```txt
apps/backend/app/base_modules/Auth/routes.ts
```
## Request Flow
### Login
```txt
POST /auth/login
-> auth_login_validator
-> Admin.findBy('email')
-> hash.verify(password)
-> Admin.accessTokens.create(admin)
-> return { type, token, user }
```
### Current User
```txt
GET /auth/user
-> auth middleware
-> auth.use('api').user
-> load roles
-> query role_permissions
-> return { user, permissions }
```
## Validation
Login validator:
```txt
apps/backend/app/base_modules/Auth/validators/auth_login_validator.ts
```
Current rules:
- `email`: trimmed email string.
- `password`: trimmed string with minimum length 8.
## Token Guard
Auth config:
```txt
apps/backend/config/auth.ts
```
The admin model is configured as the token user provider:
```txt
apps/backend/app/base_modules/Admin/model/admin.ts
```
## Response Contracts
Login response consumed by frontend:
```ts
type LoginResponse = {
type: "bearer";
token: string;
user: unknown;
};
```
Current-user response consumed by frontend:
```ts
type GetUserResponse = {
user: {
id: number;
email: string;
firstName: string;
lastName: string;
status: string;
createdAt: string;
roles: Array<{ id: number; name: string }>;
};
permissions: string[];
};
```
## Ownership Rules
- Auth backend owns token creation, token invalidation, and current-user response shape.
- Admin backend owns admin persistence and profile updates.
- Permission data in `/auth/user` is derived from role-permission rows.
+127
View File
@@ -0,0 +1,127 @@
# Auth Frontend
The frontend module implements authentication screens, session provider, current-user loading, and route guards.
Source: `apps/admin/src/core/Auth/`
## Directory Structure
```txt
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:
```txt
config/routing.tsx
```
Mounted module path:
```txt
/auth/*
```
| Route | Page | Purpose |
| -------------- | ------------ | --------------------- |
| `/auth/signin` | `SignInPage` | Admin sign-in screen. |
The index route redirects to `signin`.
## AuthProvider
Provider file:
```txt
providers/AuthProvider/AuthProvider.tsx
```
Exposes:
```ts
auth;
user;
loading;
login(email, password);
logout();
verify();
getUser();
updateUser(payload);
saveAuth(auth);
setUser(user);
```
Important behavior:
- `login` stores the access token, then loads the current user.
- `verify` reloads current user when a token exists.
- `logout` calls the backend, clears auth state, and clears React Query cache.
- `updateUser` calls `/admin/update-profile` and updates current user state.
## API Boundary
Raw API calls:
```txt
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:
```txt
data/mappers/userMapper.ts
```
## Token Storage
Token persistence helpers live in:
```txt
data/stores/localStorage.ts
```
Keep token storage behind these helpers so storage format changes stay local.
## Route Guard
Auth guard widget:
```txt
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:
```txt
config/messages.ts
config/translation/en.json
config/translation/uk.json
```
Use only `AUTH.*` keys inside this module.