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.
GET /api/verify-token is the canonical way to check whether a user’s session is still valid. It is protected by the authRequired middleware, which verifies the cookie’s signature before the handler ever runs. If the token is intact, the controller decodes the id from the payload, fetches the latest user record from the database, and returns it. This makes the endpoint suitable for bootstrapping your front-end on page load — a single call tells you both that the token is valid and delivers fresh profile data.
Endpoint
token HTTP-only cookie. The authRequired middleware processes the cookie before the controller runs.
Request Body
No request body is required or accepted for this endpoint.Authentication Flow
The request passes through two layers of verification:authRequiredmiddleware — readsreq.cookies.token, verifies the JWT signature withSECRET_KEY, and attaches the decoded payload toreq.user. Rejects the request early if the token is absent or invalid.verifyTokencontroller — additionally re-readsreq.cookies.token, callsverifyToken(token)to extract theid, then queriesUserModel.find(id)to confirm the user still exists in the database.
Example Request
Responses
200 — Valid Session
The token is valid, the user exists in the database, and the full profile is returned.The user’s UUID.
The user’s full name.
The user’s username.
The user’s email address.
The user’s phone number.
ISO 8601 timestamp of the user’s most recent login.
401 — No Token
Returned by the controller whenreq.cookies.token is falsy (absent or empty string).
401 — Invalid Token
Returned whenjwt.verify() throws (expired or tampered signature) or when UserModel.find(id) returns no matching user.
The
authRequired middleware may intercept the request before the controller logic runs. In that case the error shape is slightly different: { "message": "No Token, Unauthorized" } (missing cookie) or { "message": "Invalid Token" } (bad signature), both with HTTP 401/403 respectively. Design your client to handle either shape for this endpoint.Common Use Case
CallGET /api/verify-token once when your application initialises — for example in a React useEffect or a SvelteKit load function — to silently restore the user’s authenticated state from the persisted cookie: