Docs

getSessionList()

Retrieves a list of sessions.

function getSessionList: (queryParams: QueryParams) => Promise<PaginatedResourceResponse<Session[]>>;

QueryParams

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.

  • Name
    offset?
    Type
    number
    Description

    The number of results to skip.

type SessionStatus = "abandoned" | "active" | "ended" | "expired" | "removed" | "replaced" | "revoked";
ValueDescription
abandonedThe session was abandoned client-side.
activeThe session is valid and all activity is allowed.
endedThe user signed out of the session, but the Session remains in the Client object.
expiredThe period of allowed activity for this session has passed.
removedThe user signed out of the session and the Session was removed from the Client object.
replacedThe session has been replaced by another one, but the Session remains in the Client object.
revokedThe application ended the session and the Session was removed from the Client object.

getSessionList() examples

getSessionList({ userId })

Retrieve a list of sessions for a specific userId:

const userId = 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56';

const response = await clerkClient.sessions.getSessionList({ userId });

getSessionList({ userId, 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_2V7JJKmoA9HqzHhfMqK5cpgLl56';

const status = 'expired'

const response = await clerkClient.sessions.getSessionList({ userId, status });

console.log(response);
/*
{
  data: [
    _Session {
      id: 'sess_2agTqj42O0jJYtiToTJJ2zybWOQ',
      clientId: 'client_2ZUtYQ0PhlbbMC6WSo7zwMCPihy',
      userId: 'user_2V7JJKmoA9HqzHhfMqK5cpgLl56',
      status: 'expired',
      lastActiveAt: 1705100946532,
      expireAt: 1705344214310,
      abandonAt: 1707331414310,
      createdAt: 1704739414310,
      updatedAt: 1705101240159
    }
  ],
  totalCount: 1
}
*/

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint GET/sessions. See the BAPI reference for more details.

Feedback

What did you think of this content?