Ecommerce Delivery uses a JWT-based authentication strategy: when a user signs in, the server returns a token and a user object that are both stored in the browser’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/ecommerce-delivery-frontend/llms.txt
Use this file to discover all available pages before exploring further.
localStorage. Every subsequent API request attaches the token in an Authorization: Bearer header. Three utility functions in src/tools/User.js — validateUser, ValidateSession, and getDataUser — handle session validation, redirect logic, and user-data retrieval throughout the app.
Session storage
After a successful login or registration, the application saves two keys tolocalStorage:
token— The raw JWT string used as theAuthorizationheader on every authenticated request.user— A JSON-serialized object containing the user’s id, name, email, roles array, and membership details.
localStorage.clear()) when a session expires or the user is unauthorised.
validateUser(data)
validateUser is called before any protected API request. It reads the current user from localStorage, checks whether their role satisfies the required role(s), and returns either the enriched user object (with the token attached) or false.
| Parameter | Type | Description |
|---|---|---|
data.rol | number | number[] | The role value(s) permitted to proceed. Pass a single number or an array for OR logic. |
{ ...dataUser, token } when the check passes; false when it fails.
The admin shortcut: if the stored user’s first role has value == 2 (admin), validateUser returns the full user+token object immediately, regardless of data.rol.
ValidateSession(res, router)
ValidateSession is called after every API response. It inspects the response’s status code and, on a 401 or 403, clears the session and navigates to /login.
| Parameter | Type | Description |
|---|---|---|
res | object | The parsed API response — must contain a code property. |
router | VueRouter | The Vue Router instance obtained from useRouter(). |
false and performs the redirect on 401/403; returns true for all other responses.
getDataUser()
getDataUser retrieves the current user and token from localStorage and returns them as a single merged object. If no user key is present, it returns a safe guest (Invitado) default so that downstream code never has to guard against null.
localStorage.setItem on every call, ensuring the storage key is always populated before the guest default is used.
Auth flow
POST /api/user/login
The sign-in form submits
{ email, password } to POST /api/user/login. A successful response includes response.token and response.user.When no user is stored in
localStorage, validateUser falls back to a guest default with role value: "1" (usuario) and a cancelled membership — pages that require elevated roles will correctly return false for this guest. getDataUser uses a separate guest default with role value: "4" (Invitado) and additional profile fields such as address, phone_number, and email. Both defaults have a cancelled membership (status.code: 3).