Lex Consultoría’s frontend implements a JWT-based authentication flow: the user submits credentials to a REST endpoint, the server returns a signed token, and the client stores that token inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/despacho-frontend/llms.txt
Use this file to discover all available pages before exploring further.
localStorage for inclusion in all subsequent protected API calls. Three utility functions in src/tools/User.js — validateUser, ValidateSession, and getDataUser — centralize all session logic so no page needs to re-implement token parsing or role checking from scratch.
Login Flow
User submits credentials
The
signInComponent.vue collects an email address and password through a Quasar form. On submission the authsignUp handler fires and sends the credentials as JSON to the login endpoint:Token is stored in localStorage
When the response includes a
token field the value is persisted under the key "token". No additional parsing or verification happens on the client side — the raw JWT string is stored as-is.Success notification and redirect
A Quasar
Notify toast confirms the login, and Vue Router pushes the user to /dashboard:Role System
Every user object stored underlocalStorage.getItem("user") includes a roles array. Each role entry has a name string and a numeric value:
| Value | Name | Description |
|---|---|---|
1 | usuario | Standard authenticated user. Passes role checks when rol 1 is required. |
2 | admin | Administrator. Bypasses all role checks — validateUser returns the user+token object immediately without inspecting allowed roles. |
4 | Invitado | Guest. Default role applied by getDataUser when localStorage contains no user entry. |
validateUser(data) — Pre-Request Role Check
Call validateUser before any protected fetch to confirm the current session is authorized for the required role. It reads both "user" and "token" from localStorage, short-circuits for admins, and performs an intersection check for everyone else.
Signature
A single role value or an array of role values that are permitted to make this request. Example:
{ rol: 1 } allows standard users; { rol: [1, 4] } allows both users and guests.token string if the session passes, or false if the user lacks the required role.
Source
ValidateSession(res, router) — Post-Response Session Check
Call ValidateSession immediately after parsing an API response to detect token expiry or permission errors. If the backend returns HTTP-style codes 401 or 403 inside the JSON body, the function clears the session and redirects to /login.
Signature
The parsed JSON response object from the API. Must contain a
code field that the server sets to 401 (unauthenticated) or 403 (forbidden) when the token is invalid or expired.The Vue Router instance obtained from
useRouter(). Used to programmatically navigate to /login on session failure.true when the session is still valid; false after redirecting and clearing storage.
Source
The loose equality checks (
==) intentionally handle both string and numeric code values, since some API responses serialize the code as a string (e.g., "401") rather than a number.getDataUser() — Hydrate Session State
Call getDataUser at component mount when you need the full user profile without gating on a specific role. It reads "user" and "token" from localStorage and, if no user entry exists, seeds localStorage with a default guest object before returning it. This ensures every part of the app always receives a coherent user object.
Signature
token. For unauthenticated visitors the returned object represents the guest default.
Source
Guest Fallbacks
Each function has its own built-in fallback for whenlocalStorage contains no "user" entry.
validateUser uses a minimal fallback with role value "1" (usuario):
getDataUser uses a richer fallback with role value "4" (Invitado):
Because
validateUser’s fallback carries role value "1", an unauthenticated visitor will pass a { rol: 1 } check when no "user" key is present in localStorage. Always ensure protected pages set the user entry during sign-in so that the actual authenticated role is used for all subsequent checks.Usage Example — Dashboard Pre-Flight Check
dashboardPage.vue demonstrates the complete pattern: validate role before building headers, then call ValidateSession on every API response.
