Account security response
Temporarily prevent a compromised or suspicious account from signing in.
Clerk · Module
Locks a Clerk user so they cannot sign in until the lock expires or is manually removed. The backend method accepts a user ID and returns the affected User object.
Call the Backend SDK's users.lockUser method with a Clerk user ID. It returns the updated User object, while the user remains unable to sign in until the lock expires or an administrator unlocks the account.
function lockUser(userId: string): Promise<User>| Name | Type | Description |
|---|---|---|
userId | string | The ID of the user to lock. |
Promise<User>
import { clerkClient } from '@clerk/backend'
const userId = 'user_123'
const user = await clerkClient.users.lockUser(userId)
console.log(user.id)Locks the specified user and logs the returned user's ID.
Temporarily prevent a compromised or suspicious account from signing in.
Enforce an administrative suspension without deleting the user.
Apply a lock from backend moderation or risk-detection workflows.
It locks the specified Clerk user and returns a Promise<User>. The user cannot sign in again while the lock is active.
Follow-up: Where is the default duration configured? In the application's System settings under Protect > Rules, where the lockout duration can be changed.
The method accepts one parameter, userId, whose type is string. This is the Clerk ID of the user to lock.
Follow-up: What resource does the SDK method act on? It is a wrapper around the Backend API endpoint POST/users/{user_id}/lock.
Use clerkClient.users.lockUser(userId) in backend code and await the returned promise. The resolved value is the locked user's User object.
Follow-up: What should be checked before calling it? Ensure the application obtains the intended Clerk user ID and that the call runs through the appropriate backend SDK setup.
clerkClientusers.unlockUserUser