Skip to main content

POST /api/auth/register

Registers a new user in the system and returns a JWT authentication token.

Endpoint

POST /api/auth/register
Authentication: None (Public endpoint)

Request Body

nombre
string
required
User’s full name
  • Minimum length: 2 characters
  • Will be trimmed of whitespace
email
string
required
User’s email address
  • Must be a valid email format
  • Must be unique (not already registered)
  • Will be normalized to lowercase
password
string
required
User’s password
  • Minimum length: 6 characters
  • Will be hashed before storage using bcrypt

Response Fields

success
boolean
required
Indicates if the registration was successful
message
string
required
Success message: “Usuario registrado exitosamente”
data
object
required
Registration result data

Response Examples

{
  "success": true,
  "message": "Usuario registrado exitosamente",
  "data": {
    "user": {
      "id": "507f1f77bcf86cd799439011",
      "nombre": "Juan Pérez",
      "email": "[email protected]"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Example Request

curl -X POST http://localhost:3001/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Juan Pérez",
    "email": "[email protected]",
    "password": "miPassword123"
  }'

Error Codes

CodeMessageCause
400El email ya está registradoThe email is already in use
400Errores de validaciónRequired fields missing or invalid format
500Error interno del servidorDatabase error or other unexpected error

POST /api/auth/login

Authenticates an existing user and returns a JWT token.

Endpoint

POST /api/auth/login
Authentication: None (Public endpoint)

Request Body

email
string
required
User’s email address
  • Must be a valid email format
  • Will be normalized to lowercase
password
string
required
User’s password
  • Must match the password set during registration

Response Fields

success
boolean
required
Indicates if the login was successful
message
string
required
Success message: “Login exitoso”
data
object
required
Login result data

Response Examples

{
  "success": true,
  "message": "Login exitoso",
  "data": {
    "user": {
      "id": "507f1f77bcf86cd799439011",
      "nombre": "Juan Pérez",
      "email": "[email protected]"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Example Request

curl -X POST http://localhost:3001/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "miPassword123"
  }'

Error Codes

CodeMessageCause
401Credenciales inválidasEmail not found or incorrect password
400Errores de validaciónRequired fields missing or invalid format
500Error interno del servidorDatabase error or other unexpected error

Using the Token

After successful registration or login, use the returned token in the Authorization header for protected endpoints:
curl http://localhost:3001/api/components/export \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
The token is valid for 7 days by default (configurable via JWT_EXPIRES_IN environment variable).

Build docs developers (and LLMs) love