Session

@Serializable
data class Session(val id: String, val status: Session.SessionStatus, val expireAt: Long, val abandonAt: Long, val lastActiveAt: Long, val latestActivity: SessionActivity? = null, val lastActiveOrganizationId: String? = null, val actor: String? = null, val user: User? = null, val publicUserData: PublicUserData? = null, val createdAt: Long, val updatedAt: Long, val lastActiveToken: TokenResource? = null)

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 sessions 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.

The SessionWithActivities object is a modified Session object. It contains most of the information that the Session object stores, adding extra information about the current session's latest activity.

The additional data included in the latest activity are useful for analytics purposes. A SessionActivity object will provide information about the user's location, device and browser.

While the SessionWithActivities object wraps the most important information around a Session object, the two objects have entirely different methods.

Constructors

Link copied to clipboard
constructor(id: String, status: Session.SessionStatus, expireAt: Long, abandonAt: Long, lastActiveAt: Long, latestActivity: SessionActivity? = null, lastActiveOrganizationId: String? = null, actor: String? = null, user: User? = null, publicUserData: PublicUserData? = null, createdAt: Long, updatedAt: Long, lastActiveToken: TokenResource? = null)

Types

Link copied to clipboard

Represents the status of a session.

Properties

Link copied to clipboard
@SerialName(value = "abandon_at")
val abandonAt: Long

The time when the session was abandoned by the user.

Link copied to clipboard
val actor: String? = null

The JWT actor for the session.

Link copied to clipboard
@SerialName(value = "created_at")
val createdAt: Long

The time the session was created.

Link copied to clipboard
@SerialName(value = "expire_at")
val expireAt: Long

The time the session expires and will cease to be active.

Link copied to clipboard
val id: String

A unique identifier for the session.

Link copied to clipboard

Convenience accessor to tell if the given session is the current device. Used mostly for constructing the User profile security view.

Link copied to clipboard
@SerialName(value = "last_active_at")
val lastActiveAt: Long

The time the session was last active on the client.

Link copied to clipboard
@SerialName(value = "last_active_organization_id")
val lastActiveOrganizationId: String? = null

The last active organization identifier.

Link copied to clipboard
@SerialName(value = "last_active_token")
val lastActiveToken: TokenResource? = null

The last active token for the session.

Link copied to clipboard
@SerialName(value = "latest_activity")
val latestActivity: SessionActivity? = null

The latest activity associated with the session.

Link copied to clipboard
@SerialName(value = "public_user_data")
val publicUserData: PublicUserData? = null

Public information about the user that this session belongs to.

Link copied to clipboard

The current state of the session.

Link copied to clipboard
@SerialName(value = "updated_at")
val updatedAt: Long

The last time the session recorded activity of any kind.

Link copied to clipboard
val user: User? = null

The user associated with the session.

Functions

Link copied to clipboard

Deletes the current session.

Link copied to clipboard
suspend fun Session.fetchToken(options: GetTokenOptions = GetTokenOptions()): ClerkResult<TokenResource, ClerkErrorResponse>

Fetches a fresh JWT for the session.

Link copied to clipboard

Revokes the current session.