Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ytabeloved/ordervista/llms.txt

Use this file to discover all available pages before exploring further.

Ordervista uses a role-based access control system to ensure every user can only reach the parts of the application relevant to their responsibilities. When a user authenticates, the backend signs a JWT that embeds the user’s id_rol claim. Every protected API route then validates that claim against an allowlist of permitted role IDs before processing the request. This model keeps the three user types — Administrator, Operator, and Customer — cleanly separated without requiring separate authentication systems.

Administrator

Full system access: manage users, products, categories, and view analytics reports.

Operator

Operational access: manage active orders, kitchen commands, and generate receipts.

Customer

Self-service access: browse the menu, place online orders, and track order history.

Role IDs

Each role is stored in the ROLES table and referenced by the id_rol field on every user record. The numeric ID is embedded directly into the JWT payload so the middleware can authorize requests without an extra database lookup.
Role IDRole NameDescription
1AdministratorFull access to user management, catalog, and reporting.
2OperatorAccess to order management, kitchen commands, and receipts.
3CustomerAccess to the menu, cart, order placement, and personal order history.

How Role Enforcement Works

After the verifyToken middleware decodes the JWT and attaches the payload to req.user, the authorizeRoles(...allowedRoles) middleware checks whether req.user.id_rol is included in the list of roles permitted for that route. If the check fails, the server responds with 403 Forbidden before the route handler is ever called.
/*
    Verifica que el usuario tenga alguno de los roles permitidos.
*/
function authorizeRoles(...allowedRoles) {

    return (req, res, next) => {

        if (!req.user) {
            return res.status(401).json({
                mensaje: "Usuario no autenticado"
            });
        }

        if (!allowedRoles.includes(req.user.id_rol)) {
            return res.status(403).json({
                mensaje: "No tiene permisos para acceder a este recurso"
            });
        }

        next();
    };
}

module.exports = authorizeRoles;
Both middleware functions are composed per-route in Express — verifyToken always runs first to validate the token signature and expiry, then authorizeRoles runs to check the role claim.
Role 1 (Administrator) is the only role that can manage users, categories, and products, and the only role with access to the reports dashboard. Operators and Customers cannot reach any of these endpoints.

Build docs developers (and LLMs) love