Users-Permissions Session Management#
The Users & Permissions plugin exposes two content-API endpoints for listing and revoking a user's active device sessions. These endpoints are only available when the plugin is configured to use jwtManagement: 'refresh' mode โ they return 404 in legacy-support (default) mode.
Prerequisites#
Session endpoints require the refresh JWT management mode. Set it in /config/plugins:
module.exports = () => ({
'users-permissions': {
config: {
jwtManagement: 'refresh',
},
},
});
See the JWT management modes documentation for full configuration options including token lifespans and cookie settings.
Endpoints#
Both endpoints are registered in the content-API auth routes file and require an authenticated request (valid Authorization: Bearer <access-token> header). All session data is scoped to the currently authenticated user.
GET /api/auth/sessions โ List active sessions#
Returns all active sessions for the authenticated user. The controller:
- Calls
strapi.sessionManager('users-permissions').listSessions(userId)โ an origin-scoped wrapper that queriesadmin::sessionrecords withactivestatus, ordered bycreatedAtdescending. - Passes each session through
sanitizeSessionEntryto strip tokens and internal fields, exposing only: sessionid, optional device metadata, acurrentflag (true for the calling session), andlastActiveAt. - Sorts via
sortSessionsForDisplayโ current session first, then by most recentlastActiveAt.
Response shape:
{
"data": [
{
"id": "<sessionId>",
"current": true,
"lastActiveAt": "...",
"metadata": { "userAgent": "..." }
}
]
}
DELETE /api/auth/sessions/:sessionId โ Revoke a session#
Revokes a single session by ID. The controller calls revokeSessionById(userId, sessionId), which verifies that the session belongs to the authenticated user and the users-permissions origin before deleting it. Returns 404 if no matching owned session is found, or { data: {} } on success.
Related: Bulk Logout (POST /api/auth/logout)#
The POST /api/auth/logout endpoint complements the per-session revocation by supporting bulk revocation:
- Default (no body): revokes only the current session identified by the access token or refresh cookie.
{ "scope": "all" }: invalidates all sessions for the user.{ "deviceId": "<id>" }: invalidates sessions for a specific device.
Implementation Reference#
| Layer | Location |
|---|---|
| Route definitions | content-api/auth.js |
Controller handlers (getSessions, revokeSession) | controllers/auth.js |
| Session manager service (core) | packages/core/core/src/services/session-manager.ts |
Response utilities (sanitizeSessionEntry, sortSessionsForDisplay) | packages/core/utils/src/sessions.ts |
Session database schema (admin::session โ strapi_sessions) | packages/core/admin/server/src/content-types/session.ts |
Key Behaviors#
- Strict ownership:
revokeSessionByIdchecks both user ID and origin (users-permissions) before deleting โ a user cannot revoke sessions belonging to another user or to the admin panel. - No tokens in responses:
sanitizeSessionEntrystrips all token values and raw database IDs; the only identifier exposed is the logical sessionid. - IP not exposed: An earlier version of these endpoints included IP address in session metadata; this was subsequently removed.
- Shared session store: Sessions are persisted in
strapi_sessions(theadmin::sessioncontent type), shared between the admin panel and the users-permissions plugin, distinguished by origin.