useAuthenticatedKnockClient
The useAuthenticatedKnockClient hook is used to create and manage an authenticated Knock client instance for making API calls on behalf of a specific user.
Parameters
#This hook accepts positional parameters:
The public API key for the environment.
User identification data. Can be a string user ID or an object with id and optional properties.
Optional user token for the authenticated user.
Optional configuration for the authenticated Knock client.
Returns
#Returns a Knock client instance directly (not wrapped in an object).
Example
#Basic usage
#The following example demonstrates how to use the useAuthenticatedKnockClient hook to create an authenticated Knock client.
With options
#You can pass additional options for the Knock client:
Deferring activity with the enabled option
#The options object accepts an enabled flag that defaults to true. When it's false, the hook creates the client but keeps it idle β no identify call, no API requests, and no websocket β until you have a complete identity. Set it to true to connect like a login, and back to false to disconnect like a logout.
This is the same lifecycle the enabled prop on KnockProvider manages for you. Prefer the prop when you're using KnockProvider, and reach for this option when you build a headless client with the hook.
Using string user ID (deprecated)
#While you can pass a string user ID directly, it's recommended to use an object: