SS Restaurant uses JSON Web Tokens (JWT) for stateless authentication. You exchange a valid email and password for a signed token atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/FloresJesus/SS_RESTAURANT/llms.txt
Use this file to discover all available pages before exploring further.
/api/auth/login, then include that token in the Authorization: Bearer <token> header on every subsequent request. Tokens are valid for 8 hours from the moment of issue and carry the user’s id, email, and rol as claims, allowing both the backend middleware and the frontend router to make access decisions without an additional database round-trip.
Login
Send aPOST request to /api/auth/login with the user’s credentials. The endpoint is unauthenticated — no token is needed to call it.
- Request
- 200 — Success
- Error Responses
Method:
URL:
Content-Type:
POSTURL:
/api/auth/loginContent-Type:
application/json| Field | Type | Required | Description |
|---|---|---|---|
email | string | ✅ | The user’s registered email address |
password | string | ✅ | The user’s plaintext password (bcrypt-compared server-side) |
Using the Token
Every protected API endpoint requires the token to be sent in theAuthorization header using the Bearer scheme.
Store the token after login
Persist the token (and optionally the user object) in
localStorage immediately after a successful login response. The SS Restaurant frontend stores both keys token and user.Attach the token to every request
Pass the token in the In JavaScript, the
Authorization header. Using curl:apiFetch utility automatically reads the token from localStorage and attaches it to every outgoing request:Handle expired or invalid tokens
When the API returns a non-OK response,
apiFetch reads the response body as text and throws an Error regardless of status code. For 401 responses specifically, it also clears both localStorage keys (token and user) and redirects to /login before throwing. Non-401 errors (including 403 from an expired token) are thrown directly without redirecting, so your component’s catch block will receive them.Token Expiry
Tokens are signed withexpiresIn: "8h" and include an exp claim set 8 hours from the time of issue.
jwt.verify in verifyToken throws a TokenExpiredError and the middleware responds with:
Active User Check
Login enforces that the user’sactivo column is true before generating a token. Accounts deactivated in the admin panel receive a 401 immediately — they cannot obtain new tokens. Existing tokens for a deactivated user remain valid until expiry unless JWT_SECRET is rotated or the token is otherwise invalidated.
activo field is also returned as a boolean in the login response so the frontend can reflect the account status in the UI.
Audit Logging
Every successful login is written to the audit log vialogAudit before the response is sent. The log entry records:
| Field | Value |
|---|---|
usuario_id | The authenticated user’s id |
accion | LOGIN |
tabla | usuarios |
registro_id | The user’s id |
detalle | Inicio de sesion: <email> |
direccion_ip | Client IP address (resolved via req.ip, with trust proxy enabled) |
The server sets
app.set("trust proxy", 1) so that req.ip correctly resolves the originating client address when running behind a reverse proxy or load balancer, rather than logging the proxy’s IP.GET /api/audit by users with the admin role. See the Roles Overview page for the full list of role-protected endpoints.