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.
Docs
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'
}
});| Property | Type | Required | Description |
|---|---|---|---|
queryParams.page | string | no | Page number |
queryParams.size | string | no | Page size |
queryParams.sort | string | no | Sort, for example iat:desc |
queryParams.filter | string | no | Filter, for example status:eq:Active |
search
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' });| Property | Type | Required | Description |
|---|---|---|---|
sid | string | yes | The session id |
revoke
Revokes another session of the user. Its tokens stop working immediately.
await bshEngine.authSessions.revoke({ sid: 'session-id' });| Property | Type | Required | Description |
|---|---|---|---|
sid | string | yes | The 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 });
}
}