Session methods
These are all methods on the Clerk class that help you manage the active session and/or organization.
setSession()
(deprecated)
function setSession( session: Session | string | null, beforeEmit?: BeforeEmitCallback ): Promise<void>;
Deprecated in favor of setActive()
.
Set the current session on this client to the provided session. The provided session can be either a complete Session
object or simply its unique identifier.
Passing null as the session will result in the current session to be removed from the client.
If an active session already exists, it will be replaced with the new one. The change happens in three steps:
- The current
Session
object is set toundefined
, which causes the control components to stop rendering their children as though Clerk is still initializing. - The
beforeEmit
callback is executed. If aPromise
is returned, Clerk waits for thePromise
to resolve. - The current
Session
is set to the passedsession
. This causes the control components to render their children again.
Properties
Name | Type | Description |
---|---|---|
session | Session | string | null | A Session object or Session ID string to be set as the current session, or null to simply remove the active session, without setting a new one. |
beforeEmit? | (session: Session | null) => Promise<any> | Callback that will trigger when the current session is set to undefined , before finally being set to the passed session. Usually used for navigation. |
Returns
Type | Description |
---|---|
Promise<void> | The Promise will resolve after the passed session is set. |
setActive()
function setActive({ session, organization, beforeEmit, }: SetActiveParams): Promise<void>;
A method used to set the active session and/or organization.
SetActiveParams
Name | Type | Description |
---|---|---|
session | Session | string | null | The session resource or session ID (string version) to be set as active. If null , the current session is deleted. |
organization | Organization | string | null | The 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. |
Returns
Type | Description |
---|---|
Promise<void> | The Promise will resolve after the passed session or organization is set. |