Skip to main content

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.

The GET /api/ endpoint returns the complete profile of the currently authenticated user. Once a valid token cookie is present in the request — issued automatically during login or registration — this endpoint queries the database for the corresponding user record and returns all profile fields: id, name, email, phone, role, username, and last_login.
This endpoint requires authentication. The token cookie must be present and valid. It is set automatically when you call POST /api/login or POST /api/register and expires after 7 days.

Endpoint

MethodPathAuth Required
GET/api/✅ Yes

Authentication

This endpoint is protected by the authRequired middleware. The middleware reads the token cookie from the incoming request, verifies the JWT signature, and attaches the decoded payload (including id) to req.user. No request body or query parameters are needed.
CookieTypeDescription
tokenstringJWT issued by POST /api/login or POST /api/register. httpOnly, secure, sameSite: none.

Request

No request body is required for this endpoint.

How It Works

  1. authRequired middleware decodes the token cookie and sets req.user.id.
  2. AuthController.get calls UserModel.find(id), which executes:
    SELECT * FROM users WHERE id = ?
    
  3. If a matching row is found, the controller returns the user’s profile fields as JSON.
  4. If no row is found, a 404 response is returned.

Response Fields

id
string
required
The unique UUID of the user, generated at registration time via randomUUID().
name
string
required
The user’s full display name as provided during registration.
email
string
required
The user’s email address. Must be unique across all accounts.
phone
string
required
The user’s phone number. Must be unique across all accounts.
role
string | null
The user’s assigned role. Returns null if no role has been assigned to the account.
username
string
required
The user’s unique username used for login. Must be unique across all accounts.
last_login
string
required
ISO 8601 timestamp of the user’s most recent successful login, updated by POST /api/login.

Success Response

Status: 200 OK
{
  "id": "uuid-string",
  "name": "Jane Doe",
  "email": "jane@example.com",
  "phone": "555-123-4567",
  "role": null,
  "username": "janedoe",
  "last_login": "2024-01-15T10:30:00.000Z"
}

Error Responses

StatusBodyCause
401{ "message": "No Token, Unauthorized" }No token cookie was included in the request.
403{ "message": "Invalid Token" }The token cookie is present but has an invalid signature or has expired.
404{ "message": "Usuario no encontrado" }The user ID decoded from the JWT does not match any record in the database.

Code Examples

curl -X GET https://your-api-domain.com/api/ \
  --cookie "token=<your_jwt_token>"

Build docs developers (and LLMs) love