Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

Session methods

These methods on the Clerk class help you manage the active session and/or organization.

setActive()

A method used to set the active session and/or organization.

function setActive({ session, organization, beforeEmit, }: SetActiveParams): Promise<void>;

SetActiveParams

NameTypeDescription
session?Session | string | nullThe session resource or session ID (string version) to be set as active. If null, the current session is deleted.
organization?Organization | string | nullThe organization resource or organization ID (string version) to be set as active in the current session. If null, the currently active organization is removed as active.
beforeEmit?(session?: Session | null) => void | Promise<any>Callback run just before the active session and/or organization is set to the passed object. Can be used to hook up for pre-navigation actions.

setActive() example

The setActive() method is most commonly used when building a custom flow for your application.

For example, during authentication, when a user signs in or signs up successfully, a new session is created. setActive() needs to be used to set the new session as the active session. See the implementation of this in the Custom authentication flow guide.

Another example is when a user switches organizations in a multi-organization application. setActive() needs to be used to set the new organization as the active organization. See the implementation of this in the Custom organization switcher guide.

Last updated on March 8, 2024

What did you think of this content?

Clerk © 2024