Skip to content

useMongocampSessions ​

The signed-in user's own sessions (server 3.0, AUTH_SESSIONS=true). Used by the Sessions card of MongocampAccount.

ts
const { list, revoke, revokeOthers } = useMongocampSessions()
const rows = await list() // SessionRow[] | null — null: the server has no sessions
await revoke(rows[1].id)
await revokeOthers(rows) // every session but the current one
  • list() — GET /auth/sessions (15 s timeout) as rows { id, current, device, ip, createdAt, lastUsedAt, expiresAt } (times in ms, 0 = unknown): the current session first, then the most recently used. device is a short name from the user agent (Chrome · macOS, Safari · iOS; an unknown agent as it is, at most 60 characters; '' without one — utils/sessions.ts deviceLabel). A server without sessions answers the route with 404, which resolves null.
  • revoke(id) — DELETE /auth/sessions/{id}: the session's refresh token and its access tokens stop working at once (on other server instances within 5 minutes). A session that is already gone (404) counts as ended.
  • revokeOthers(rows) — revoke for every row that is not current, one request each, stops at the first refusal; answers how many it ended. The server's own DELETE /auth/sessions ends the current session too — for "sign out everywhere" use the dependency's useMongocampAuth().revokeAllSessions(), which also clears the local session.

The refresh itself is the dependency's: with sessions its useMongocampAuth() refreshes through the httpOnly cookie mongocamp_refresh (same origin: the embedded server or a proxy) when the mongocamp.refreshToken option is on. A refresh token used a second time after the grace period ends the whole session (401, code 4014) — the dependency logs out, and MongocampErrorAlert says the session was ended elsewhere.

Not available in server proxy mode (there is no login).

Released under the MIT License.