This endpoint is used to register a new user in the system. It validates the input data, hashes the password, and creates a new user record in the database. Upon successful registration, it returns a JSON Web Token (JWT) and the user details.
POST
The request body should be a JSON object with the following structure:
{
"fullname": {
"firstname": "string (min 3 characters, required)",
"lastname": "string (min 3 characters, optional)"
},
"email": "string (valid email format, required)",
"password": "string (min 6 characters, required)"
}{
"token": "string (JWT token)",
"user": {
"_id": "string",
"fullname": {
"firstname": "string",
"lastname": "string"
},
"email": "string",
"socketId": "string (optional)"
}
}Occurs when validation fails or required fields are missing.
{
"errors": [
{
"msg": "string (error message)",
"param": "string (field name)",
"location": "string (body)"
}
]
}fullname.firstname: Must be at least 3 characters long and is required.fullname.lastname: Must be at least 3 characters long and is optional.email: Must be a valid email format and is required.password: Must be at least 6 characters long and is required.
curl -X POST http://localhost:3000/users/register \
-H "Content-Type: application/json" \
-d '{
"fullname": {
"firstname": "John",
"lastname": "Doe"
},
"email": "john.doe@example.com",
"password": "password123"
}'{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"_id": "64f1c2e5b5d6c2a1e8f7a9b3",
"fullname": {
"firstname": "John",
"lastname": "Doe"
},
"email": "john.doe@example.com",
"socketId": null
}
}{
"errors": [
{
"msg": "Invalid email format",
"param": "email",
"location": "body"
}
]
}