This API provides functionality for managing users including user registration, authentication, user details retrieval, user updates, and password management.
- URL:
/api/users - Method:
POST - Description: Register a new user.
- Request Body:
username: Username of the user.email: Email address of the user.password: Password for the user.address: (Optional) Address of the user.phoneNumber: (Optional) Phone number of the user.photo: (Optional) Profile photo of the user.role: (Optional) Role of the user (default: 'buyer').
- Response:
user: User object containing user details excluding password.token: JWT token for authentication.
- URL:
/api/auth/login - Method:
POST - Description: Authenticate a user.
- Request Body:
emailorusername: Email address or username of the user.password: Password for the user.
- Response:
user: User object containing user details excluding password.token: JWT token for authentication.
- URL:
/api/users/:userID - Method:
GET - Description: Get details of a specific user.
- Response:
user: User object containing user details excluding password.
- URL:
/api/users - Method:
GET - Description: Get details of all users.
- Response:
users: Array of user objects containing user details excluding password.
- URL:
/api/users/:userID - Method:
PATCH - Description: Update details of a specific user.
- Request Body:
- Fields to be updated (e.g.,
username,email,address,phoneNumber,photo,role).
- Fields to be updated (e.g.,
- Response:
user: Updated user object containing user details.
- URL:
/api/users/:userID - Method:
DELETE - Description: Delete a specific user.
- URL:
/api/users/password - Method:
POST - Description: Update the password of a user.
- Request Body:
currentPassword: Current password of the user.newPassword: New password for the user.
- URL:
/api/users/password - Method:
POST - Description: Request a password reset OTP.
- Request Body:
email: Email address of the user.
- URL:
/api/auth/reset-password - Method:
POST - Description: Reset the password using OTP.
- Request Body:
email: Email address of the user.otp: One-time password sent to the user's email.newPassword: New password for the user.
- Errors are returned with appropriate HTTP status codes and error messages in JSON format.