Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nelrondon/backend-proyecto-estructuras/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/login verifies a user’s credentials, issues a fresh JWT, and writes it into an HTTP-only cookie valid for 7 days. It also updates the last_login timestamp in the database so you always have an accurate record of the most recent session. On success the response body includes the full user profile, allowing your client to hydrate its auth state immediately without an additional network call.
Endpoint
Request Body
The username registered with the account. The model performs a case-sensitive lookup:
SELECT * FROM users WHERE username = ?.The account password in plain text (over HTTPS). The server compares it against the stored
bcrypt hash using bcrypt.compare().Behaviour
- The request body is validated with Zod’s
validatePartialUser(a.partial()variant of the full schema) — onlyusernameandpasswordare required here. - The model queries the database for the given
username. bcrypt.compare()is called against the storedpassword_hash.- On a successful match,
last_loginis updated viaUPDATE users SET last_login = ? WHERE id = ?. - A new 7-day JWT is signed with
{ id: user.id }as the payload and set as thetokencookie.
Example Request
Responses
200 — Success
Thetoken cookie is set (7-day expiry) and the response body carries the authenticated user’s profile.
The user’s UUID.
The user’s full name.
The user’s username.
The user’s email address.
The user’s phone number.
The timestamp of this login, set to
new Date() at the moment the model runs. This value is also written back to the database.422 — Validation Error
Returned whenusername or password is missing or fails its Zod type check.
500 — User Not Found
Returned when no user with the givenusername exists in the database.
500 — Wrong Password
Returned whenbcrypt.compare() returns false for the supplied password.
Both “user not found” and “wrong password” return HTTP 500 in the current implementation. Clients should inspect the
error string to distinguish between the two cases.