Sign-in and account (Admin)
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
Executive summary
Section titled “Executive summary”Admin sign-in and password reset (forgot → OTP → new password) use the NestJS API. Registration remains a simulated SPA flow (no backend call). This page maps routes and expectations.
Goals and non-goals
Section titled “Goals and non-goals”| Goals | Non-goals |
|---|---|
| Give operators a single map of auth URLs and behaviors | Guarantee self-service registration without backend support |
| Call out in-memory OTP / multi-instance caveats | Document Laravel legacy auth internals |
Current platform behavior
Section titled “Current platform behavior”/— public marketing landing (no JWT); loadsGET /api/v1/public/landing-settingsfor document title, meta tags, and hero text (fallbacks + i18n)./login— sign-in (real API)./forgot-password,/verify-otp,/reset-password— real password reset (see Authentication and API paths below)./register— simulated only.- JWT and admin profile semantics: Authentication, Admin panel overview.
Sequence: happy path
Section titled “Sequence: happy path”- User opens
/login(or follows Sign in from/) → enters credentials → receives JWT → redirect to/dashboard. - Forgot password →
POST /api/v1/auth/admin/password-reset→ enter OTP on/verify-otp→POST …/verifyreturnsreset_token→/reset-password→POST …/complete.
Security and operations
Section titled “Security and operations”- Use HTTPS in production; never expose admin tokens in screenshots or shared URLs.
- Prefer org-owned provisioning for high-privilege admins; review register availability before exposing publicly.
Test scenarios (UAT / QA)
Section titled “Test scenarios (UAT / QA)”| ID | Scenario | Expected |
|---|---|---|
| AA1 | Valid login | Lands on /dashboard with working session |
| AA2 | Bad password | Clear error; no silent success |
| AA3 | Forgot password + OTP + reset | Valid account: OTP path works; invalid email still shows generic success (anti-enumeration) |
Routes
Section titled “Routes”| Path | Purpose |
|---|---|
/ | Marketing landing (public); Sign in → /login |
/login | Sign in |
/register | Registration UI (see limitations below) |
/forgot-password | Request password recovery |
/verify-otp | OTP entry (see limitations below) |
/reset-password | Set a new password (see limitations below) |
Source: apps/admin-web/src/routes/app-router.tsx.
Sign in (/login)
Section titled “Sign in (/login)”The login form calls the backend POST /auth/admin/login with email, password, and admin_type:
admin_employee— staff (default toggle in the UI).admin— super / non-employee admin (second toggle).
On success, the app stores access and refresh tokens and profile fields in a persisted Zustand store (nipos-admin-auth), then navigates to /dashboard. It optionally calls GET /auth/admin/me to refresh the profile.
If you already have a valid access token (after hydration), visiting / or /login redirects to /dashboard.
Protected dashboard
Section titled “Protected dashboard”Routes under /dashboard require a JWT. Unauthenticated users are sent back to /login, with the intended path preserved for redirect after login (see ProtectedRoute).
Password reset (real API)
Section titled “Password reset (real API)”Flow uses admin-password-reset-api.ts with skipAuthHandler: true so OTP errors do not trigger JWT refresh.
- Request:
POST /api/v1/auth/admin/password-reset—{ "email", "admin_type" }(admin_employee|admin). Response is always a generic success message. - Verify:
POST /api/v1/auth/admin/password-reset/verify—{ "email", "admin_type", "code" }→{ "reset_token" }. /verify-otpUI: one field for the full 6-digit code (non-digits are stripped on submit; paste andone-time-codeautofill supported).- Complete:
POST /api/v1/auth/admin/password-reset/complete—{ "reset_token", "password" }(min 8 characters).
Session storage (sessionStorage) carries email, admin_type, and reset_token between steps. Operational caveats (in-memory OTP, logging): Authentication.
Registration (simulated)
Section titled “Registration (simulated)”/register still uses timeouts and navigates to /dashboard without a backend call. Treat as non-production; prefer Master Admin / IT provisioning (see Admin panel overview).
Session and tokens
Section titled “Session and tokens”The SPA attaches the access token to API requests and uses refresh handling shared with src/lib/api.ts. For token lifecycle and endpoints, see Authentication.
Related
Section titled “Related”- Admin panel overview — audience and modules.
- Roles — module access.
- Authentication — JWT, refresh,
/me.