Overview
Admin endpoints for user management, including listing all users and updating user roles.
All endpoints on this page require admin role authentication via the requireAdmin middleware.
List Users
Retrieve a paginated list of all users in the system.
Query Parameters
Page number for pagination
Response
Indicates if the request was successful
Array of user objects
User role: "user" or "admin"
ISO 8601 timestamp of account creation
{
"success": true,
"data": [
{
"id": "user_123abc",
"email": "[email protected]",
"name": "John Doe",
"role": "user",
"createdAt": "2024-01-15T10:30:00.000Z"
},
{
"id": "user_456def",
"email": "[email protected]",
"name": "Admin User",
"role": "admin",
"createdAt": "2024-01-10T08:00:00.000Z"
}
],
"pagination": {
"currentPage": 1,
"totalPages": 5,
"totalItems": 50,
"limit": 10
}
}
Update User Role
Update a user’s role. Admins can promote users to admin or demote admins to regular users.
Path Parameters
Request Body
New role for the user. Must be either "user" or "admin"
Response
Indicates if the role was updated successfully
{
"success": true,
"message": "User role updated successfully"
}
Request Example
curl -X PUT https://api.example.com/api/admin/users/user_123abc/role \
-H "Content-Type: application/json" \
-H "Cookie: session=..." \
-d '{
"role": "admin"
}'
const response = await fetch('/api/admin/users/user_123abc/role', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify({
role: 'admin'
})
});
const data = await response.json();
Validation Rules
- Role must be either
"user" or "admin"
- User ID must exist in the database
- Admins cannot change their own role (prevents accidental lockout)
- Returns 400 for validation errors
- Returns 404 if user not found
- Returns 500 for server errors