Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/Ecommerce/llms.txt

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

The Ecommerce API supports two authentication strategies: JWT (JSON Web Token) as the primary method, and Google OAuth 2.0 as a social sign-in alternative. Both strategies ultimately issue a signed JWT that clients include on every protected request. Understanding which routes are public and which require a valid token is the first step to integrating with the API.

Authentication methods

JWT Authentication

Register an account, verify your email with a 5-digit code, log in, and receive a long-lived token for all subsequent requests.

Google OAuth 2.0

Sign in with an existing Google account. The API uses Passport.js to handle the OAuth flow and issues the same JWT on success.

JWT authentication flow

Regardless of which method you use to sign in, every protected endpoint expects the same token-access header. The full lifecycle for the native JWT path is:
1

Register

Call POST /api/user/register to create an inactive account.
2

Verify email

Submit the 5-digit code sent to your email to POST /api/user/verify-account to activate the account.
3

Log in

Call POST /api/user/login to receive your JWT.
4

Attach the token

Pass the token in the token-access request header on every call to a protected route.

Passing the token

All protected endpoints are guarded by the Token middleware, which reads a custom header — not the standard Authorization header. The expected format is:
token-access: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
The header name is token-access, not Authorization. Requests that use Authorization: Bearer … will be rejected with a 403 response.

Token payload

When you decode a token issued by this API you will find the following fields:
FieldTypeDescription
idstringMongoDB _id of the user document
userNamestringDisplay name chosen at registration
emailstringEmail address
phonestringPhone number
sexstringGender field from the user profile
documentstringIdentity document number
documentTypestringType of identity document
birthdatestringDate of birth
rolesarrayArray of role objects (see Roles)
activatearrayArray of activation status objects

Token expiry

Tokens are valid for 365 days from the moment they are issued. There is currently no refresh-token mechanism; after expiry the user must log in again to obtain a new token.
The issued token is stored on the User document in the database. The Token middleware verifies the signature and confirms that the corresponding user document still exists before granting access.

User roles

The API uses a simple role system embedded in the token payload.
Role nameValuePermissions
Usuario"1"Standard access — browse and purchase products
Admin"2"Manage products, view all users, admin operations

Account activation status

Status nameValueMeaning
Inactivo"2"Account created but not yet verified
Activado"1"Email verified, account is active
Only accounts with status Activado can log in and receive a token.

Public vs. protected routes

The table below lists every authentication-related route and whether it requires a token.
MethodEndpointAuth requiredDescription
POST/api/user/registerNoCreate a new inactive user account
POST/api/user/verify-accountNoActivate account with 5-digit code
POST/api/user/loginNoLog in and receive JWT
POST/api/user/recovery-passwordNoSend password-reset code to email
POST/api/user/update-passwordNoReset password using the code
GET/auth/googleNoInitiate Google OAuth flow
GET/auth/google/callbackNoGoogle OAuth callback (handled internally)
All product management endpoints and user-listing endpoints require the token-access header. Admin-only routes additionally validate that the roles array contains the Admin role (value: "2").

Error responses

The Token middleware returns the following errors when authentication fails:
HTTP StatusConditionResponse body
403token-access header is missing{ "msj": "Sin token" }
401Token signature is invalid or malformed{ "msj": "Token inexistente", "status": false }
404Token is valid but the user no longer exists{ "msj": "Sin usuario" }

Build docs developers (and LLMs) love