MultiSas recognises two types of authenticated principals: the Company (the tenant owner, registered by the Super Admin) and the UserCompany (sub-users created by a company’s Admin to represent employees, sellers, or consultants). Both principals authenticate using JWTs delivered in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/MultiSas/llms.txt
Use this file to discover all available pages before exploring further.
token-access header, but they carry different role fields and are stored in separate MongoDB collections. Every protected route enforces the caller’s role through the TokenAuthorize middleware, which runs after the token has been validated and req.user has been populated.
Company Roles
Therole_user field on the Company document is an enum with four possible values:
| Role | Description |
|---|---|
Super Admin | Platform-level administrator. Registers companies, assigns and manages subscription plans, and has read/write access across all tenants. There is typically one Super Admin for the entire MultiSas deployment. |
Admin | Company administrator. Manages all resources within their own company — products, clients, invoices, employees — and creates and activates sub-users (UserCompany). |
Vendedor | Seller role. Scoped to sales and client-facing operations within the company. Cannot manage other users or plan settings. |
Sin rol | Default value assigned on registration. A company with this role has no functional permissions until the Super Admin explicitly assigns a role. |
UserCompany Roles
Sub-users have their own role field —role_user_company — with a separate enum defined on the UserCompany model:
| Role | Description |
|---|---|
Vendedor | Seller — can perform sales and client lookups within the parent company |
Consultor | Consultant — typically read-oriented access for reporting or analysis |
Diseñador | Designer — access to template and presentation-layer features |
Sin rol | Default — no permissions until the Admin assigns a role |
nit_company_by_user field on the UserCompany document mirrors the parent company’s nit_company, providing a secondary linkage by tax ID in addition to the company foreign key (which holds the parent’s _id).
How Role Enforcement Works
TheTokenAuthorize(...roles) middleware accepts a variadic list of allowed roles and returns a handler that checks the authenticated principal’s role against that list. It handles both Company and UserCompany principals transparently by inspecting req.user.type_dato:
TokenAuthorize performs the following checks in order:
- Principal lookup — re-fetches the Company or UserCompany document from the database to ensure the role has not changed since the JWT was issued.
- Role check — verifies that
role_user(orrole_user_company) is included in therolesarray passed to the middleware. - Active check (UserCompany only) — verifies that
data_user.active === truebefore allowing the request through.
| Condition | HTTP Status | Response body |
|---|---|---|
| Role not in allowed list | 403 | {"msj": "No tienes permisos", "status": false} |
UserCompany active === false | 403 | {"msj": "Usuario inactivo", "status": false} |
| Company document not found | 404 | {"msj": "Empresa no encontrada", "status": false} |
| UserCompany document not found | 404 | {"msj": "Usuario de empresa no encontrado", "status": false} |
Account Activation
A newly createdUserCompany document has active: false by default. Until an Admin explicitly activates the sub-user, TokenAuthorize will reject every request from that account with {"msj": "Usuario inactivo", "status": false}. Activation is performed by the company Admin (or Super Admin):
active boolean on the UserCompany document. The same endpoint can be used to deactivate a sub-user if their access should be revoked — the active field is set back to false and all subsequent requests from that JWT are rejected.
TokenAny vs Token vs TokenUserCompany
Choosing the right token middleware
Choosing the right token middleware
MultiSas exposes three token-validation middlewares. Each one determines which type of JWT is accepted and what gets written to
req.user.Token
Accepts only a Company JWT. Looks up the caller in the Company collection. Use this on routes that should never be accessible to sub-users, such as internal Super Admin management endpoints.TokenUserCompany
Accepts only a UserCompany JWT. Looks up the caller in the UserCompany collection. Use this on routes that are exclusively for sub-users and should reject Company-level tokens.TokenAny
Accepts either a Company JWT or a UserCompany JWT. It tries the Company collection first; if no match is found, it tries UserCompany. The resolved principal type is stored in req.user.type_dato ("company" or "user_company"), which TokenAuthorize uses to apply the correct role check. This is the most flexible option and is the standard choice for any endpoint that both Admins and sub-users should be able to call.