Skip to Content
🎉 BSH Engine v0.0.7 is out with new features and improvements. See what's new →

Auth Sessions Service

The Auth Sessions Service lists, inspects and revokes the auth sessions of the logged-in user, for example to build a “Devices” or “Active sessions” screen.

These methods require a user login (JWT or cookie session); API keys are rejected. Regular users only see their own sessions, while BSH_ADMIN users see the sessions of every user. See Auth Sessions API.

Methods

current

Returns the session the SDK is currently authenticated with.

const response = await bshEngine.authSessions.current({}); const session = response?.data[0];

list

Lists sessions with query parameters.

await bshEngine.authSessions.list({ queryParams: { page: '0', size: '10', sort: 'iat:desc', filter: 'status:eq:Active' } });
PropertyTypeRequiredDescription
queryParams.pagestringnoPage number
queryParams.sizestringnoPage size
queryParams.sortstringnoSort, for example iat:desc
queryParams.filterstringnoFilter, for example status:eq:Active

Searches sessions with a BSH Search payload.

await bshEngine.authSessions.search({ payload: { filters: [{ field: 'status', operator: 'eq', value: 'Active' }] } });

details

Gets a session by id.

await bshEngine.authSessions.details({ sid: 'session-id' });
PropertyTypeRequiredDescription
sidstringyesThe session id

revoke

Revokes another session of the user. Its tokens stop working immediately.

await bshEngine.authSessions.revoke({ sid: 'session-id' });
PropertyTypeRequiredDescription
sidstringyesThe session id

The current session can’t be revoked; use bshEngine.auth.logout instead.

count / countFiltered

Counts all visible sessions, or the ones matching a search payload.

await bshEngine.authSessions.count({}); await bshEngine.authSessions.countFiltered({ payload: { filters: [{ field: 'status', operator: 'eq', value: 'Active' }] } });

Session metadata

Each session has an optional metadata object with the device and app it was created From.

To fill client, give your app a name when creating the engine. The SDK then sends it as the X-Bsh-Client header:

const bshEngine = new BshEngine({ host: 'https://your-instance.com', clientName: 'My App', });

The values the engine can return are exported as BshSessionMetaData, for example to map each device type to an icon:

import { BshDevice, BshSessionMetaData } from '@bshsolutions/sdk/types'; const deviceIcons: Record<BshDevice, string> = { Desktop: '🖥️', Mobile: '📱', Tablet: '📱', Other: '⌨️', }; const response = await bshEngine.authSessions.list({}); for (const session of response?.data ?? []) { const meta = session.metadata ?? {}; console.log(meta.device ? deviceIcons[meta.device] : '❔', meta.label ?? 'Unknown device'); } BshSessionMetaData.browsers; // ['Edge', 'Opera', ..., 'Python']

Example: sign out other devices

const response = await bshEngine.authSessions.list({ queryParams: { filter: 'status:eq:Active' } }); for (const session of response?.data ?? []) { if (!session.current) { await bshEngine.authSessions.revoke({ sid: session.sid }); } }
Last updated on