Skip to main content

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. Use the useClerk() hook to access the clerk object, as shown in the following example.

app/routes/index.tsx
import { useClerk } from '@clerk/tanstack-react-start'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: Home,
})

export default function Home() {
  // Use the useClerk hook to access the clerk object
  const clerk = useClerk()

  // Access the client object
  const client = clerk.client

  return <pre>{JSON.stringify(client, null, 2)}</pre>
}
  • Name
    captchaBypass
    Type
    boolean
    Description

    Indicates whether CAPTCHA checks are skipped for this client.

  • Name
    cookieExpiresAt
    Type
    null | Date
    Description

    The date and time when the client's authentication cookie will expire.

  • Name
    createdAt
    Type
    null | Date
    Description

    The date and time when the client was created.

  • Name
    id?
    Type
    string
    Description

    The unique identifier of the resource.

  • 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; null when 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.

  • Name
    updatedAt
    Type
    null | Date
    Description

    The date and time when the client was last updated.

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(): void

create()

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(): boolean

isNew()

Indicates whether this client hasn't been saved (created) yet in the Frontend API.

function isNew(): boolean

reload()

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>
  • Name
    rotatingTokenNonce?
    Type
    string
    Description

    A nonce to use for rotating the user's token. Used in native application OAuth flows to allow the native client to update its JWT once despite changes in its rotating token.

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(): void

resetSignUp()

Resets the current sign-up attempt. Clears the in-progress sign-up state on the client.

function resetSignUp(): void

Feedback

What did you think of this content?

Last updated on