SS Restaurant uses a role-based access control (RBAC) system that governs what every authenticated user can see and do — both on the backend (Express route-level middleware) and on the frontend (Vue Router navigation guards). Every user stored in theDocumentation 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.
usuario table carries a rol column, and that value is embedded in their JWT at login. All protected API routes validate the token and, where needed, check that the user’s role is in an explicitly allowed set before proceeding.
Roles at a Glance
There are four roles in the system. Each role maps to a named set of features available in both the sidebar navigation and the underlying API endpoints.| Role | Features |
|---|---|
admin | Dashboard, Customers, Menu, Orders, Tables, Reservations, Employees, Reports, Settings, Audit |
cajero | Dashboard, Orders, Payments |
mesero | Dashboard, Customers, Menu, Orders, Tables, Reservations |
cocina | Dashboard, Orders |
ROLE_ACCESS constant in the Vue Router configuration mirrors this table exactly and is the single source of truth for the frontend:
Backend Enforcement
Every protected route inserver.js is guarded by one or both of the following middleware functions.
verifyToken — JWT Validation
verifyToken reads the Authorization header, extracts the Bearer token, and verifies it using JWT_SECRET. On success it attaches the decoded payload to req.user so downstream middleware and route handlers can read req.user.id, req.user.email, and req.user.rol. If the decoded payload does not include a rol claim (for example, tokens issued by an older version of the server), it performs a database lookup via findUserById to hydrate the role.
checkRole — Role Authorization
checkRole is a factory function that accepts an array of allowed role strings and returns a middleware. It is always chained after verifyToken (so req.user is guaranteed to exist) and returns 403 if the user’s role is not in the allowed list.
How Middleware Is Applied in server.js
Routes that need only authentication pass verifyToken alone. Routes that additionally restrict access to specific roles chain checkRole([...]) immediately after.
Frontend Enforcement
The Vue Router navigation guard runsbeforeEach on every route change. It reads the token and user object from localStorage, then applies two checks in sequence:
- Authentication check — if no token is present the visitor is redirected to
/login. - Role check — if the target route has a
meta.rolesarray and the user’srolis not in it, the guard redirects to/(the dashboard).
meta.roles field:
The Pinia auth store (
useAuthStore) exposes convenience getters — isAdmin, isCajero, isMesero, and isCocina — that components can use for conditional rendering. These are derived from state.user.rol and are separate from the router guard.API-Level Restrictions
The table below documents the effective access policy as registered inserver.js. Routes listed as All authenticated require a valid token for any of the four roles.
| Endpoint | Required Role(s) |
|---|---|
GET/POST/PUT/DELETE /api/users | admin |
GET/POST/PUT/DELETE /api/settings | admin |
GET /api/reports | admin |
GET /api/audit | admin |
GET/POST/PUT/DELETE /api/payments | admin, cajero |
GET/POST/PUT/DELETE /api/tickets | admin, cajero |
GET/POST/PUT/DELETE /api/invoices | admin, cajero |
GET/POST/PUT/DELETE /api/customers | All authenticated |
GET/POST/PUT/DELETE /api/menu | All authenticated |
GET/POST/PUT/DELETE /api/tables | All authenticated |
GET/POST/PUT/DELETE /api/reservations | All authenticated |
GET/POST/PUT/DELETE /api/orders | All authenticated |
GET/POST/PUT/DELETE /api/notifications | All authenticated |
Public Routes
A small set of routes is intentionally unauthenticated to support customer-facing features.GET /api/public/menu
Returns the publicly visible menu. Used by the online reservation page and any embedded menu widget. No token required.
POST /api/public/reservations
Accepts reservation requests from guests. Powers the
/reservar frontend route. No token required./login
The frontend login page. The Vue Router guard explicitly skips the authentication check for this path and redirects already-authenticated users to
/./reservar
The public-facing guest reservation form. The Vue Router guard unconditionally allows navigation to this path regardless of authentication state.