Sign-in & shared code
Sign in
| Path | /login |
|---|---|
| Status | live |
| Drill-down pages | /forgot-password |
| Pop-ups | — |
| Tabs | — |
| API routes | /api/auth/login/api/auth/me |
Business rules
Data comes from: dh_users (one row per login) and dh_user_access (its page keys). Server: POST /api/auth/login, then GET /api/auth/me on every page load.
How it works:
- Email (case and spaces ignored) and password. Wrong email or wrong password both answer "Invalid credentials", so the page never says which one was wrong.
- An invited login (no password yet) is told to use its "Set up your Pulse account" email. An inactive login gets "Account is inactive".
- Lockout: 10 wrong passwords within 15 minutes locks the login for 15 minutes ("Too many attempts — try again in 15 minutes"). Locks and unlocks are written to the Audit Log (
utils/login-lockout.ts). - On success: a session token valid for 12 hours, and
last_login_atis updated. A staff login that still owes its staff information is sent to that form first. - Each browser IP may try 5 times a minute (see Rate limits).
- After a session ends (signed out elsewhere, password changed, idle), the page says "Your session ended. Please sign in again." Once you sign in, it goes back to the page you were on. Only pages inside Pulse are allowed as the return address.
- A missing or broken request gets "Email and password required" (400), not a server error.
Database tables & columns
| Table | Columns used |
|---|---|
dh_user_access | access_key, position, user_id |
dh_users | access, created_at, email, failed_login_count, failed_login_window_start, id, last_login_at, locked_until, name, password_changed_at, password_hash, role, staff_id, status, updated_at |
staff | id, onboarding_completed_at |
File structure
Its own files
- apps/
- web/
- src/
- contexts/
- AuthContext.tsx
- pages/
- Login.tsx
- contexts/
- src/
- web/
Shared code it uses (followed through its imports and the helpers its API calls; sign-in/access plumbing and UI primitives left out)
- apps/
- web/
- src/
- lib/
- safe-return.ts
- lib/
- src/
- worker/
- src/
- db/
- index.ts
- routes/
- auth.ts
- services/
- session.ts
- user-access.ts
- utils/
- jwt-key.ts
- login-lockout.ts
- password.ts
- db/
- src/
- web/