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.

POST /api/register creates a brand-new user record in the database. The request body is validated against the full Zod userSchema before any database work begins. If validation passes and no conflicts exist, the server hashes the password with bcrypt, inserts the row, signs a 7-day JWT, and writes it into an HTTP-only cookie — all in a single round-trip. The JSON response immediately gives you the new user’s profile so you can bootstrap your UI without a second request.

Endpoint

POST /api/register
Authentication: None required.

Request Body

name
string
required
The user’s full name. Must not contain any numeric characters (0–9). Validated by the regex /[0-9]/ — if a digit is found the request is rejected with a 422.
email
string
required
A valid email address (e.g. john@example.com). Validated with Zod’s .email() rule. Must be unique across all registered users.
phone
string
required
A phone number matching the pattern (\+?\d{1,3}[-. ]?)?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}. Accepts formats such as +1-800-555-1234, (800) 555 1234, or 8005551234. Must be unique across all registered users.
username
string
required
The user’s chosen username. Must be unique across all registered users.
password
string
required
The account password (plain text over HTTPS). The server hashes it with bcrypt before storing — the raw password is never persisted.

Uniqueness Constraint

Before inserting, the model runs:
SELECT * FROM users WHERE username = ? OR email = ? OR phone = ?
If any row is returned, registration is aborted and the server responds with 500 and { "error": "Username, email o teléfono ya registrados." }.

Example Request

curl -c cookies.txt -s -X POST https://your-api.com/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com",
    "phone": "+1-800-555-1234",
    "username": "johndoe",
    "password": "secret123"
  }'

Responses

200 — Success

The token cookie is set in the response headers. The body contains the newly created user’s profile.
id
string
UUID assigned to the new user (generated with crypto.randomUUID()).
name
string
The user’s full name as provided in the request.
username
string
The username chosen during registration.
email
string
The user’s email address.
phone
string
The user’s phone number.
last_login
string
ISO 8601 timestamp set to CURRENT_TIMESTAMP at the moment of insertion.
{
  "id": "a3f8c2d1-74be-4e2a-9f61-bb0123456789",
  "name": "John Doe",
  "username": "johndoe",
  "email": "john@example.com",
  "phone": "+1-800-555-1234",
  "last_login": "2024-11-01T14:32:00.000Z"
}

422 — Validation Error

Returned when any field fails Zod schema validation. The first validation message is extracted from the error array and returned directly.
{
  "error": "El nombre no debe contener números"
}

500 — Conflict or Server Error

Returned when the username, email, or phone is already registered, or when the INSERT statement fails for any other reason.
{
  "error": "Username, email o teléfono ya registrados."
}
All three fields — username, email, and phone — are checked in a single query using OR. If any one of them is already in the database the entire registration is rejected, even if only one field conflicts.

Build docs developers (and LLMs) love