getSessionList()
Retrieves a list of sessions. Returns a PaginatedResourceResponse object with a data property that contains an array of Session objects, and a totalCount property that indicates the total number of sessions for the specified user.
function getSessionList(
queryParams: SessionListParams,
): Promise<PaginatedResourceResponse<Session[]>>SessionListParams
getSessionList() requires either clientId or userId to be provided.
- Name
clientId?- Type
string- Description
The client ID to retrieve the list of sessions for.
- Name
userId?- Type
string- Description
The user ID to retrieve the list of sessions for.
- Name
status?- Type
SessionStatus- Description
The status of the session.
- Name
limit?- Type
number- Description
The number of results to return. Must be an integer greater than zero and less than 501. Can be used for paginating the results together with
offset. Defaults to10.
- Name
offset?- Type
number- Description
Skip the first
offsetresults when paginating. Needs to be an integer greater or equal to zero. To be used in conjunction withlimit. Defaults to0.
type SessionStatus =
| 'abandoned'
| 'active'
| 'pending'
| 'ended'
| 'expired'
| 'removed'
| 'replaced'
| 'revoked'Retrieve a list of sessions for a specific userId:
const userId = 'user_123'
const response = await clerkClient.sessions.getSessionList({ userId })Filter by session status
In this example, a list of sessions with a status of 'expired' is retrieved. You can see that the returned PaginatedResourceResponse includes data, which is an array of Session objects, and totalCount, which indicates the total number of sessions for the specified user.
const userId = 'user_123'
const status = 'expired'
const response = await clerkClient.sessions.getSessionList({ userId, status })Backend API (BAPI) endpoint
This method in the SDK is a wrapper around the BAPI endpoint GET/sessions. See the BAPI reference for more information.
Feedback
Last updated on