Retrieve session details
Backend session lookup
Clerk · Pipe
sessionId is the string ID of a Clerk session. Pass it to the backend getSession() method to retrieve that session.
A session ID is the string identifier Clerk uses to select a particular session. Backend session operations accept it to retrieve session data, generate a token, or verify session-related information.
function getSession(sessionId: string): Promise<Session>| Name | Type | Description |
|---|---|---|
sessionId | string | The ID of the session to get. |
A Promise that resolves to the requested Session.
getSession() retrieves the session resource associated with the supplied identifier.sessionId parameter is a string containing the target session's ID.Session object.const sessionId = 'sess_123'
const response = await clerkClient.sessions.getSession(sessionId)
console.log(response)Retrieves a Clerk session by its identifier using the backend SDK.
Backend session lookup
Authentication administration
Session-aware server logic
sessionId used for in Clerk's backend session API?sessionId is a string that identifies the Clerk session to retrieve. The backend SDK uses it with sessions.getSession() to return the corresponding Session object.
Follow-up: How would you generate a token for that session? Call clerkClient.sessions.getToken(sessionId, template?); the optional template selects a configured JWT template.
getSession()?The real signature is function getSession(sessionId: string): Promise<Session>. It accepts one required string and asynchronously returns the matching session.
Follow-up: What does the SDK method wrap? It wraps the Backend API request to GET /sessions/{session_id}.
Use a session identifier such as sess_123 and pass it to clerkClient.sessions.getSession(). The result is the session resource, whose properties can then be inspected by the backend application.
Follow-up: How can the same identifier be used for tokens? Pass it to getToken(), optionally alongside a JWT template name and expiration setting.
SessionclerkClient.sessions.getToken()clerkClient.sessions.verifySession()GET /sessions/{session_id}