Client object
The Client object keeps track of the authenticated sessions in the current device. The device can be a browser, a native application, or any other medium that is usually the requesting part in a request/response architecture.
The Client object also holds information about any sign-in or sign-up attempts that might be in progress, tracking the sign-in or sign-up progress.
Example
The Client object is available on the Clerk object.
import { Clerk } from '@clerk/clerk-js'
const publishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
// Initialize Clerk with your Clerk Publishable Key
const clerk = new Clerk(publishableKey)
// Load Clerk
await clerk.load()
// Access the client object
await clerk.client- Name
-
lastActiveSessionId - Type
null | string- Description
The ID of the last active Session on this client.
- Name
-
lastAuthenticationStrategy - Type
null | LastAuthenticationStrategy- Description
The last authentication strategy used by this client;
nullwhen unknown or feature disabled.
- Name
-
sessions - Type
SessionResource[]- Description
A list of sessions that have been created on this client.
- Name
-
signedInSessions - Type
SignedInSessionResource[]- Description
A list of sessions on this client where the user has completed the full sign-in flow. Sessions can be in one of the following states:
"active": The user has completed the full sign-in flow and all pending tasks."pending": The user has completed the sign-in flow but still needs to complete one or more required steps (pending tasks).
- Name
-
signIn - Type
- SignInResource
- Description
The current sign-in attempt.
- Name
-
signUp - Type
- SignUpResource
- Description
The current sign-up attempt.
Methods
buildTouchUrl()
Builds a URL that refreshes the current client's authentication state and then redirects the user to the specified URL.
function buildTouchUrl(params: { redirectUrl: URL }): string- Name
params- Type
{ redirectUrl: URL; }- Description
The URL to redirect the user to.
clearCache()
Clears any locally cached session data for the current client.
function clearCache(): voidcreate()
Creates a new client for the current instance along with its cookie.
function create(): Promise<ClientResource>destroy()
Deletes the client. All sessions will be reset.
function destroy(): Promise<void>isEligibleForTouch()
Indicates whether the client cookie is due to expire in 8 days or less.
function isEligibleForTouch(): booleanisNew()
Indicates whether this client hasn't been saved (created) yet in the Frontend API.
function isNew(): booleanreload()
Reloads the resource, which is useful when you want to access the latest user data after performing a mutation. To make the updated data immediately available, this method forces a session token refresh instead of waiting for the automatic refresh cycle that could temporarily retain stale information. Learn more about forcing a token refresh.
function reload(p?: ClerkResourceReloadParams): Promise<ClientResource>removeSessions()
Removes all sessions created on the client.
function removeSessions(): Promise<ClientResource>resetSignIn()
Resets the current sign-in attempt. Clears the in-progress sign-in state on the client.
function resetSignIn(): voidresetSignUp()
Resets the current sign-up attempt. Clears the in-progress sign-up state on the client.
function resetSignUp(): voidFeedback
Last updated on