Users API
The Users API provides administrative endpoints for managing user accounts, roles, bans, and sessions. All endpoints require admin authentication.Authentication
All endpoints require:- Valid session with admin role
- Admin guard (
isAdminUsercheck)
List users
number
Page number for pagination
number
Number of users per page
string
Search query for filtering users
string
Filter by role (e.g., “admin”, “moderator”)
array
Array of user objects
number
Total number of users
number
Current page number
number
Users per page
User management actions
All user management operations use the same endpoint with different action parameters. Endpoint:POST /api/admin/users
Set user role
Assign a role to a user.string
required
Must be
"set-role"string
required
Target user ID
string
required
Role to assign:
"admin", "moderator", "author", "owner", "citizen"Ban user
Ban a user account.string
required
Must be
"ban"string
required
User ID to ban
string
Reason for ban (optional but recommended)
Unban user
Remove ban from a user account.List user sessions
Get all active sessions for a specific user.Revoke user sessions
Revoke all active sessions for a user (force logout).Response codes
success
Operation successful
error
Invalid request (missing action, userId, or role)
error
Forbidden - requires admin role
error
User not found
error
Internal server error
Error responses
Implementation reference
Source:/src/pages/api/admin/users.ts
The implementation uses the following admin utilities:
listUsers()- From@lib/admin/userssetUserRole()- Role assignment with validationbanUser()- Ban with optional reasonunbanUser()- Remove banlistUserSessions()- Session enumerationrevokeUserSessions()- Force logout