go-auth
GuidesClient

Sessions

sessionsApi — a named-method wrapper around the list/revoke session endpoints, built on the apiRequest helper.

Sessions client

Wraps the list/revoke endpoints from the Sessions guide into sessionsApi, built on the apiRequest helper — same relationship as authApi has to the Authentication guide.

Looking for me()/check()?

GET /auth/me and GET /auth/check are documented on this guide's Checking who's logged in section, but the wrapped methods live on authApi.me() / authApi.check() on the Authentication client — that's where this codebase's reference frontend keeps them, and there's no reason for the two client objects to disagree with the app you're actually copying this pattern from.

import { apiRequest } from "./client";

const API_BASE = "https://api.myapp.com";

export const sessionsApi = {
  list: (offset = 0, limit = 20) =>
    apiRequest(API_BASE, "GET", `/auth/sessions?offset=${offset}&limit=${limit}`),

  listAll: () => apiRequest(API_BASE, "GET", "/auth/sessions/all"),

  revoke: (sessionId: string) =>
    apiRequest(API_BASE, "DELETE", `/auth/sessions/${sessionId}`),

  revokeMany: (sessionIds: string[]) =>
    apiRequest(API_BASE, "POST", "/auth/sessions/revoke", { session_ids: sessionIds }),

  revokeAllExceptCurrent: () => apiRequest(API_BASE, "DELETE", "/auth/sessions"),
};

Using it

const { sessions, current_session_id } = await sessionsApi.list();

const otherDevices = sessions.filter((s) => s.id !== current_session_id);
await sessionsApi.revoke(sessionId);
// refresh the list afterward — this doesn't remove it from `sessions` for you
await sessionsApi.revokeAllExceptCurrent();
// every other device is signed out; the current tab keeps working

Next

  • Setup — the apiRequest helper this is built on
  • Sessions — full request/response/error reference, and the curl cookie-jar gotcha worth reading if something isn't working

On this page