Multi-account switching
A browser user regularly switches among personal, work, and customer accounts.
Better Auth · Function
Better Auth's multi-session plugin keeps multiple account sessions active in one browser. It provides client operations for listing sessions, switching the active session, and revoking sessions.
The multi-session plugin lets one browser retain sessions for multiple accounts. Install the server and client plugins, then use the client methods to list sessions, activate one, or revoke one; the plugin defaults to five sessions per device.
multiSession(); multiSessionClient(); authClient.multiSession.listDeviceSessions(); authClient.multiSession.setActive({ sessionToken }); authClient.multiSession.revoke({ sessionToken });| Name | Type | Description |
|---|---|---|
sessionToken | string | The token identifying the session to activate. |
maximumSessions | number | The maximum number of sessions a user can have. |
listDeviceSessions returns the current user's active device sessions; setActive changes the active session; revoke removes a selected session.
import { betterAuth } from "better-auth";
import { multiSession } from "better-auth/plugins";
import { createAuthClient } from "better-auth/client";
import { multiSessionClient } from "better-auth/client/plugins";
export const auth = betterAuth({
plugins: [multiSession()],
});
export const authClient = createAuthClient({
plugins: [multiSessionClient()],
});
const sessions = await authClient.multiSession.listDeviceSessions();
await authClient.multiSession.setActive({ sessionToken: sessions.data?.[0]?.token ?? "" });Register the server and client plugins, then retrieve device sessions and activate one by its session token.
A browser user regularly switches among personal, work, and customer accounts.
An administration console lets an operator access several tenant accounts without repeated sign-ins.
A support tool needs to keep multiple customer contexts available in one browser.
The server registers multiSession(), while the browser client registers multiSessionClient(). The client plugin enables management of multiple active sessions in the browser.
Follow-up: What does the plugin use to preserve the additional sessions? It adds another browser cookie when a user logs in, and that cookie maintains the additional sessions.
Call listDeviceSessions to obtain the active sessions for the current user. Then pass a selected session's token to setActive to make it the active session.
Follow-up: Which endpoint corresponds to listing sessions? The operation uses GET /multi-session/list-device-sessions.
The plugin accepts maximumSessions to limit how many sessions a user can have. If omitted, the documented default is five sessions per device.
Follow-up: What happens when the user signs out? The existing signOut method automatically revokes all active sessions for that user.
multiSession()multiSessionClient()listDeviceSessionssetActiverevokesignOutmaximumSessions