createUser
id: createUser title: Create User​
POST /api/users
​
Create a new user. This endpoint is intended to be used by an admin to create other users. The request must be authenticated with a valid session token and the authenticated user must have the admin
role.
Request Body​
{
"name": "John Doe",
"email": "user@example.com",
"password": "yourpassword",
"role": "user" // optional, e.g. "user" or "admin"
}
Response​
-
201 Created
{ "success": true, "message": "User registered successfully" }
- The user was created successfully.
-
400 Bad Request
{ "success": false, "error": "Name, email, and password are required" }
- Missing required fields.
-
400 Bad Request
{ "success": false, "error": "Email already in use" }
- A user with the provided email already exists.
-
403 Forbidden
{ "success": false, "error": "Forbidden" }
- The authenticated user is not an admin.
-
500 Internal Server Error
{ "success": false, "error": "Internal server error" }
Example​
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
--cookie "token=your_jwt_token" \
-d '{"name":"John Doe","email":"user@example.com","password":"yourpassword","role":"user"}'