The Eco-It authentication system uses a two-step email-verification flow for new registrations, JWT-based sessions for all protected routes, and a Google OAuth 2.0 integration for single-sign-on. Password recovery is handled through a six-digit code delivered by email. All auth endpoints are rate-limited; exceeding the limit returnsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vanegasjoseignacio2-cyber/Eco-It/llms.txt
Use this file to discover all available pages before exploring further.
429 Too Many Requests.
JWTs are returned in the response body — not in cookies. Store the token in
localStorage or a secure in-memory store and attach it as Authorization: Bearer <token> on every protected request.Registration flow
User registration is a two-step process: first the server sends a verification code to the supplied email address, then the client submits that code to finalise account creation.POST /api/auth/registro is present in the router but is a deprecated stub. It always returns HTTP 400 with the message "Usa el flujo de verificación por email: /enviar-codigo-registro → /verificar-registro". Do not use this route — use the two-step flow documented below.POST /api/auth/enviar-codigo-registro
Validates the supplied data, checks for duplicate emails, hashes the password, and sends a 6-digit OTP to the provided email address. The pending registration is stored for 15 minutes. Returns 429 if a code was already sent in the last 3 minutes.
Request body
First name of the user. Must be between 2 and 50 characters.
Last name / surname of the user.
Age of the user. Must be a positive integer.
Valid email address. Must not already be registered.
Mobile phone number (validated format).
Plain-text password. Minimum 8 characters. Hashed with bcrypt (cost 12) before persisting.
true on success.Human-readable confirmation:
"Código enviado a tu correo electrónico.".POST /api/auth/verificar-registro
Verifies the 6-digit code against the pending registration record. On success the user account is created in the database, a welcome email is dispatched, and a 7-day JWT is returned. Allows a maximum of 5 incorrect attempts before the pending record is discarded.
Request body
The same email address used in
enviar-codigo-registro.The 6-digit verification code received by email.
true on successful verification and account creation."¡Cuenta verificada y creada exitosamente!"Signed JWT. Expires in 7 days. Payload:
{ id, rol, perfilCompleto }.Newly created user object.
MongoDB
_id of the user.Always
"user" for newly registered accounts.true — email-registered users always have a complete profile.POST /api/auth/reenviar-codigo-registro
Issues a fresh 6-digit code for an existing pending registration. Enforces a 3-minute cooldown between sends and resets the 15-minute expiry window.
Request body
Email address of the pending registration.
"Nuevo código enviado a tu correo." on success.Login & Logout
POST /api/auth/login
Authenticates a local (email + password) user and returns a 12-hour JWT.
Request body
Registered email address.
Plain-text password.
"Inicio de sesión correcto" on success.Signed JWT. Expires in 12 hours.
Authenticated user object — same shape as the registration response.
POST /api/auth/logout
Signals the client to discard the JWT. Since tokens are stored client-side, this endpoint simply returns a success acknowledgement — no server-side state is invalidated.
Request body — none required.
Response
Always
true."Sesión cerrada correctamente".Google OAuth
GET /api/auth/google
Initiates the Google OAuth 2.0 consent flow. Redirects the browser to Google’s authorisation page requesting the profile and email scopes. This endpoint is visited directly by the browser — it is not called with fetch or XMLHttpRequest.
No request body. No authentication required.
GET /api/auth/google/callback
Handles the OAuth callback from Google. On success, generates a 12-hour JWT and returns an HTML page that redirects the browser to:
token query parameter and store it for subsequent API calls. On failure, the browser is redirected to {FRONT_URL}/login.
No request body. Managed entirely by Passport.js and the browser redirect cycle.
Profile completion (Google OAuth users)
PUT /api/auth/completar-perfil
Google OAuth users land with perfilCompleto: false. This endpoint lets them supply the remaining fields before accessing the full application.
Authentication: Authorization: Bearer <token> required.
Request body
Last name. Must not be empty.
Age. Must be an integer between 1 and 120.
Mobile phone number in a valid format.
The full updated user document from MongoDB.
Password recovery flow
Password recovery is a three-step process using a 6-digit email code.Request a recovery code
POST /api/auth/recuperar-password — sends the code to the user’s registered email.Verify the code
POST /api/auth/recuperar-password/verificar — confirms the code is valid before letting the user type a new password.POST /api/auth/recuperar-password/reenviar issues a fresh one (3-minute cooldown).
POST /api/auth/recuperar-password
Looks up the account by email, generates a 6-digit code (SHA-256 hashed before storage), and emails it to the user. Code expires in 15 minutes.
Request body
Email address of the account to recover.
POST /api/auth/recuperar-password/verificar
Confirms that the provided code is valid and unexpired. Use this step to gate the “new password” form in the UI — it does not change the password.
Request body
Account email address.
The 6-digit code received by email.
POST /api/auth/recuperar-password/reenviar
Issues a new 6-digit code and resets the 15-minute expiry. Enforces a 3-minute cooldown between resends.
Request body
Account email address.
POST /api/auth/recuperar-password/restablecer
Final step of password recovery. Verifies the code one more time, updates the password (the model’s pre('save') hook hashes it automatically), and clears the recovery token fields.
Request body
Account email address.
The 6-digit code from the recovery email.
New plain-text password. Minimum 8 characters.
"Contraseña actualizada correctamente" on success.Error reference
| HTTP Status | Cause |
|---|---|
400 | Missing or invalid fields; duplicate email; expired or incorrect OTP; max OTP attempts reached |
401 | Wrong credentials; Google-only account attempted with password login |
404 | Email not found in the system |
429 | Rate limit exceeded (auth limiter) or resend cooldown active |
500 | Internal server error; SMTP delivery failure |