Session

@Serializable
data class Session(val id: String, val status: Session.SessionStatus = SessionStatus.UNKNOWN, val expireAt: Long, val abandonAt: Long? = null, val lastActiveAt: Long, val latestActivity: SessionActivity? = null, val lastActiveOrganizationId: String? = null, val actor: JsonElement? = null, val user: User? = null, val publicUserData: PublicUserData? = null, val factorVerificationAge: List<Int>? = null, val createdAt: Long, val updatedAt: Long, val tasks: List<SessionTask> = emptyList(), 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 = SessionStatus.UNKNOWN, expireAt: Long, abandonAt: Long? = null, lastActiveAt: Long, latestActivity: SessionActivity? = null, lastActiveOrganizationId: String? = null, actor: JsonElement? = null, user: User? = null, publicUserData: PublicUserData? = null, factorVerificationAge: List<Int>? = null, createdAt: Long, updatedAt: Long, tasks: List<SessionTask> = emptyList(), lastActiveToken: TokenResource? = null)

Types

Link copied to clipboard

Properties

Link copied to clipboard
@SerialName(value = "abandon_at")
val abandonAt: Long? = null
Link copied to clipboard
val actor: JsonElement? = null
Link copied to clipboard
@SerialName(value = "created_at")
val createdAt: Long
Link copied to clipboard
@SerialName(value = "expire_at")
val expireAt: Long
Link copied to clipboard
@SerialName(value = "factor_verification_age")
val factorVerificationAge: List<Int>? = null
Link copied to clipboard
val id: String
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
Link copied to clipboard
@SerialName(value = "last_active_organization_id")
val lastActiveOrganizationId: String? = null
Link copied to clipboard
@SerialName(value = "last_active_token")
val lastActiveToken: TokenResource? = null
Link copied to clipboard
@SerialName(value = "latest_activity")
val latestActivity: SessionActivity? = null
Link copied to clipboard
@SerialName(value = "public_user_data")
val publicUserData: PublicUserData? = null
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@SerialName(value = "updated_at")
val updatedAt: Long
Link copied to clipboard
val user: User? = null

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.