Skip to main content

Introduction

The Construction Backend API uses a secure authentication system based on email and password credentials. User passwords are hashed using bcrypt before storage to ensure maximum security.

Key Concepts

User Model Schema

The User model consists of the following fields:
FieldTypeRequiredUniqueDescription
documentStringYesYesUser’s identification document (e.g., national ID)
emailStringYesYesUser’s email address
passwordStringYesNoHashed password (bcrypt)
nameStringYesNoUser’s first name
last_nameStringYesNoUser’s last name
cellphoneStringYesNoUser’s phone number
user_typeStringYesNoType/role of user in the system

Password Security

Passwords are never stored in plain text. The system uses bcrypt with a salt round of 10 to hash all passwords before database storage.
// Password hashing implementation
const hashedPassword = await bcrypt.hash(password, 10);

Authentication Flow

1

User Registration

New users register with their credentials and personal information. The system validates uniqueness of email and document.
2

Password Hashing

The plain-text password is hashed using bcrypt before being stored in the database.
3

User Login

Users authenticate by providing email and password. The system compares the hashed password using bcrypt.
4

Session Response

Upon successful authentication, user information (excluding password) is returned to the client.

Security Features

The authentication system includes the following security measures:
  • Bcrypt password hashing (salt rounds: 10)
  • Email uniqueness validation
  • Document uniqueness validation
  • Secure password comparison
  • No password exposure in API responses

Available Endpoints

  • POST /register - Register a new user account
  • POST /login - Authenticate and login existing users

Error Handling

The API returns appropriate HTTP status codes:
  • 200 - Successful login
  • 201 - Successful registration
  • 400 - Bad request (missing fields, duplicate email/document)
  • 401 - Unauthorized (invalid credentials, user not found)
  • 500 - Server error

Next Steps

User Registration

Learn how to register new users

User Login

Learn how to authenticate users

Build docs developers (and LLMs) love