This endpoint authenticates a registered lawyer account. It looks up the account by email (case-insensitive), then uses bcrypt’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/despacho-backend/llms.txt
Use this file to discover all available pages before exploring further.
compare function to validate the supplied plaintext password against the stored hash. On a successful match, a JSON Web Token is signed with the server’s secret key and set to expire in 365 days. The token is also persisted on the user’s MongoDB document so the server can cross-reference active sessions. Both the signed token and a trimmed user object (_id, email, role) are returned in the response — no further lookup is needed by the calling client.
Request Body
The lawyer’s registered email address. Looked up case-insensitively in the
database, so
Abogado@Despacho.com and abogado@despacho.com resolve to the
same account.The account password in plaintext. Compared against the bcrypt hash stored in
the database using
bcrypt.compare — never logged or persisted during this
operation.Example Request
Responses
200 — Authentication Successful
Credentials are valid. Returns a signed JWT and the authenticated user’s details.Human-readable welcome message. Value:
"Bienvenido!".true when authentication succeeded.Signed JWT bearer token. Valid for 365 days from the moment of issue.
Include this value in the
Authorization header of all subsequent requests to
protected endpoints.A trimmed representation of the authenticated lawyer’s account.
203 — Invalid Credentials or Missing Fields
Returned for two distinct conditions:- Missing fields —
emailorpasswordwas absent from the request body.
- Wrong password — The email was found but the password did not match the stored bcrypt hash.
403 — Email Not Found
No account exists for the supplied email address.500 — Internal Server Error
An unexpected server-side or database error occurred. The raw error object is returned in the response body.Using the Token
Every protected endpoint in the Despacho API requires the JWT to be sent as a Bearer token in theAuthorization request header:
Authorization header is missing or the token is invalid/expired, protected endpoints will return a 401 Unauthorized or 403 Forbidden response.
JWT Payload
The token is a standard HS256-signed JWT. After decoding (e.g. at jwt.io), the payload contains:| Claim | Type | Description |
|---|---|---|
_id | string | MongoDB ObjectId of the authenticated lawyer |
email | string | Email address of the authenticated lawyer |
role | array | Role objects at the time the token was issued |
iat | number | Unix timestamp — when the token was issued |
exp | number | Unix timestamp — when the token expires (issued + 365 days) |
SECRET environment variable using the HS256 algorithm. Tokens cannot be validated without the correct secret.