Introduction
The Mueve API uses JWT (JSON Web Tokens) for secure authentication. All authenticated endpoints require a valid token to be included in the request headers.JWT tokens provide a stateless authentication mechanism, allowing secure API access without storing session data on the server.
Authentication Flow
User Registration
Create a new account by providing name, email, and password. Passwords are hashed using bcrypt with a salt round of 10 before storage.
User Login
Authenticate with email and password. The API validates credentials and returns a JWT token if successful.
Access Protected Resources
Include the JWT token in the
Authorization header of subsequent requests using the Bearer schema.Security Features
Password Hashing
All passwords are encrypted using bcrypt before being stored in the database. Bcrypt is a one-way hashing algorithm that provides strong protection against rainbow table attacks.JWT Token Structure
JWT tokens generated by the API contain the following payload:The unique user ID from the database
The user’s email address
Token issued at timestamp (Unix epoch)
Token expiration timestamp (Unix epoch)
Token Expiration
JWT tokens expire after 24 hours (1 day) from issuance. After expiration, users must log in again to obtain a new token.
Token Verification Middleware
Protected routes use theverifyToken middleware to validate authentication:
Using Authentication Headers
For all protected endpoints, include the JWT token in your request headers:Error Responses
401 Unauthorized - No Token Provided
401 Unauthorized - No Token Provided
401 Unauthorized - Invalid Format
401 Unauthorized - Invalid Format
403 Forbidden - Invalid or Expired Token
403 Forbidden - Invalid or Expired Token
Returned when the token is invalid, expired, or tampered with.
Best Practices
Next Steps
Register Users
Learn how to register new users
User Login
Authenticate and obtain JWT tokens