<APIKeys /> component
The <APIKeys /> component is used to manage API keys for your application. It allows you to create, edit, and revoke API keys for your application.
The component manages API keys based on the user's current context. When the user has an selected, all operations are scoped to that Organization. Otherwise, operations are user-scoped.
To utilize the <APIKeys /> component, you must first enable API keys in the Clerk Dashboard. Refer to the Using API keys guide for more information.
Usage with JavaScript
The following methods available on an instance of the Clerk class are used to render and control the <APIKeys /> component:
The following examples assume that you have followed the quickstart in order to add Clerk to your JavaScript application.
mountAPIKeys()
Render the <APIKeys /> component to an HTML <div> element.
function mountAPIKeys(node: HTMLDivElement, props?: APIKeysProps): void- Name
node- Type
HTMLDivElement- Description
The container
<div>element used to render in the<APIKeys />component
- Name
props?- Type
- APIKeysProps
- Description
The properties to pass to the
<APIKeys />component
import { Clerk } from '@clerk/clerk-js'
// Initialize Clerk with your Clerk Publishable Key
const clerkPubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
const clerk = new Clerk(clerkPubKey)
await clerk.load()
document.getElementById('app').innerHTML = `
<div id="api-keys"></div>
`
const apiKeysDiv = document.getElementById('api-keys')
clerk.mountAPIKeys(apiKeysDiv, {
perPage: 10,
showDescription: true,
})unmountAPIKeys()
Unmount and run cleanup on an existing <APIKeys /> component instance.
function unmountAPIKeys(node: HTMLDivElement): void- Name
node- Type
HTMLDivElement- Description
The container
<div>element with a rendered<APIKeys />component instance
import { Clerk } from '@clerk/clerk-js'
// Initialize Clerk with your Clerk Publishable Key
const clerkPubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
const clerk = new Clerk(clerkPubKey)
await clerk.load()
document.getElementById('app').innerHTML = `
<div id="api-keys"></div>
`
const apiKeysDiv = document.getElementById('api-keys')
clerk.mountAPIKeys(apiKeysDiv)
// ...
clerk.unmountAPIKeys(apiKeysDiv)Properties
All props are optional.
- Name
perPage?- Type
number- Description
The number of API keys to show per page. Defaults to
10.
- Name
showDescription?- Type
boolean- Description
Whether to show the description field in the API key creation form. Defaults to
false.
- Name
appearance?- Type
Appearance | undefined- Description
Optional object to style your components. Will only affect Clerk components and not Account Portal pages.
- Name
fallback?- Type
ReactNode- Description
An optional element to be rendered while the component is mounting.
Customization
To learn about how to customize Clerk components, see the customization documentation.
If Clerk's prebuilt components don't meet your specific needs or if you require more control over the logic, you can rebuild the existing Clerk flows using the Clerk API. For more information, see the custom flow guides.
Feedback
Last updated on