Custom backend client
Create a server-side Clerk client with application-specific configuration.
Clerk · Function
Creates a customized Clerk Backend API client for JavaScript environments. Provide a Clerk Secret Key in the options object, then use the returned client for server-side resources such as users and invitations.
createClerkClient() constructs a customized Backend API client for JavaScript environments. Pass an options object containing at least the Clerk Secret Key, then use the returned client to call resources such as users or invitations.
createClerkClient(options)| Name | Type | Description |
|---|---|---|
options | object | Configuration object for the client; it must include the Clerk Secret Key and may include other supported options. |
A customized Clerk client instance that wraps the Backend API.
CLERK_SECRET_KEY.import { createClerkClient } from '@clerk/backend'
const clerkClient = createClerkClient({
secretKey: process.env.CLERK_SECRET_KEY,
})
const users = await clerkClient.users.getUserList()
console.log(users)Creates a backend Clerk client with the server-side secret key, then retrieves the user list.
Create a server-side Clerk client with application-specific configuration.
Call Backend API resources such as user management operations.
Use server-side Clerk functionality from a JavaScript or TypeScript application.
It creates a wrapper around Clerk's Backend API for JavaScript environments. The returned client exposes resource APIs, such as users, for server-side operations.
Follow-up: How would you avoid exposing credentials? Pass the secret key from a server-side environment variable, such as process.env.CLERK_SECRET_KEY, and never ship it to browser code.
Call createClerkClient() with an options object and provide secretKey. The resulting client can then be used for operations such as clerkClient.users.getUserList().
Follow-up: What is a useful customization pattern? Supply additional supported options alongside secretKey when the application needs to customize the client.
The function is useful when the default clerkClient instance is not sufficient. It lets an application create a custom instance with its own options while retaining access to the Backend API.
Follow-up: When should a default instance be preferred? Use the SDK's default client when the standard environment-based configuration meets the application's needs.
clerkClientusers.getUserList()invitations.createInvitation()authenticateRequest()