Disable a user who violates application rules
Account enforcement
Clerk · Module
Use banUser() in Clerk's JavaScript Backend SDK to ban a user by ID. The operation revokes the user's sessions and blocks future sign-ins.
Call clerkClient.users.banUser() with the target user's ID from a trusted server environment. Clerk marks the user as banned, revokes every active session, prevents future sign-ins, and returns the updated User object.
function banUser(userId: string): Promise<User>| Name | Type | Description |
|---|---|---|
userId | string | The ID of the user to ban. |
Promise<User> resolving to the banned user.
clerkClient depend on the Clerk server SDK in use; follow that SDK's access pattern.import { clerkClient } from '@clerk/express'
const userId = 'user_123'
const user = await clerkClient.users.banUser(userId)
console.log(user.banned)Calls Clerk from a server-side application and prints the returned user's banned status.
Account enforcement
Security response
Moderation workflow
banUser() do?banUser(userId) marks the specified Clerk user as banned and returns a Promise<User>. Banning revokes all of that user's sessions and prevents the user from signing in again.
Follow-up: What endpoint does the helper wrap? It wraps the Backend API POST/users/{user_id}/ban.
The method accepts one parameter: userId, a string containing the ID of the user to ban. The returned promise resolves to the updated User object.
Follow-up: How would you remove the restriction? Use Clerk's corresponding unbanUser() method.
Use the server-side clerkClient and call clerkClient.users.banUser(userId). The SDK setup and import vary by the Clerk SDK used, so the application must follow that SDK's server configuration.
Follow-up: Why should the operation not run in client code? It is a privileged Backend API operation and should be performed from a trusted server environment.
unbanUser()UserclerkClientBackend API