Session object - Objects - JavaScript | Clerk Docs

Session object

The Session object is an abstraction over an HTTP session. It models the period of information exchange between a user and the server.

The Session object includes methods for recording session activity and ending the session client-side. For security reasons, sessions can also expire server-side.

As soon as a User signs in, Clerk creates a Session for the current Client. Clients can have more than one session at any point in time, but only one of those sessions will be active.

In certain scenarios, a session might be replaced by another one. This is often the case with multi-session applications.

All sessions that are expired, removed, replaced, ended or abandoned are not considered valid.

Note

For more information regarding the different session states, see the guide on session management.

Example

The Session object is available on the Clerk object.

Example Code

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 session object
const session = clerk.session

Properties

Methods

attemptFirstFactorVerification()

Attempts to complete the first factor verification⁠ process.

Returns a SessionVerification instance with its status and supported factors.

function attemptFirstFactorVerification(attemptFactor: SessionVerifyAttemptFirstFactorParams): Promise<SessionVerificationResource>

checkAuthorization()

Checks if the user is authorized for the specified Role, Permission, Feature, or Plan or requires the user to reverify their credentials if their last verification is older than allowed.

function checkAuthorization(isAuthorizedParams: CheckAuthorizationParams): boolean

clearCache()

Clears the cache for the current session. This is useful if the session has been updated and the cache is no longer valid.

function clearCache(): void

end()

Marks the session as ended. The session will no longer be active for this Client and its status will become ended.

function end(): Promise<SessionResource>

getToken()

Gets the current user's session token or a custom JWT template.

verifyWithPasskey()

Initiates a verification flow using passkeys.

Returns a SessionVerification instance with its status and supported factors.

function verifyWithPasskey(): Promise<SessionVerificationResource>

Feedback

What did you think of this content?

It's been marked as helpful and up to date.