PATIENT role.
Registration Endpoint
Required Fields
All three fields are mandatory for registration:| Field | Type | Validation | Description |
|---|---|---|---|
email | string | Valid email format | User’s email address (must be unique) |
password | string | Minimum 8 characters | User’s password |
name | string | 2-100 characters | User’s full name |
The
role field is automatically set to PATIENT during registration and cannot be specified in the request.Validation Rules
Email Validation
- Must be a valid email format
- Must be unique (not already registered)
- Validated using Joi schema (
src/schemas/usersSchema.js:5)
Password Requirements
The password is hashed using bcryptjs with a salt rounds value (default: 10) before storage:Name Validation
- Minimum length: 2 characters
- Maximum length: 100 characters
Example Request
Success Response
When registration is successful, you receive a confirmation message:201 Created
Error Responses
Missing Required Fields
Status Code:400 Bad Request
Password Too Short
Status Code:400 Bad Request
Email Already Exists
If you attempt to register with an email that’s already in use: Status Code:400 Bad Request
The error message for duplicate emails is generic to prevent email enumeration attacks.
Invalid Email Format
When the email doesn’t meet validation requirements: Status Code:400 Bad Request
Implementation Details
The registration process (src/services/authService.js:8-32) performs the following steps:
Security Features
Password Hashing
Passwords are hashed using bcryptjs before storage. The hashed password is never returned in API responses.Audit Logging
Every registration is logged in the audit system with the user ID and action type (register).
Default Role Assignment
Next Steps
After registering, you can:- Login to obtain a JWT token
- Use the token to access protected endpoints
- Learn about JWT token usage