new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Better Auth · Plugins · all subjects

multi-session plugin

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Multi Session plugin for concurrent sessions

Better Auth includes a Multi Session plugin that enables multiple concurrent sessions per user.

Multi-session plugin allows multiple active sessions in same browser

The multi-session plugin allows users to maintain multiple active sessions across different accounts in the same browser. This plugin is useful for applications that require users to switch between multiple accounts without logging out.

Multi-session plugin installation - server side

To install the multi-session plugin on the server, import multiSession from 'better-auth/plugins' and add it to the plugins array in the betterAuth configuration.

Multi-session plugin installation - client side

To enable managing multiple active sessions on the client, import multiSessionClient from 'better-auth/client/plugins' and add it to the plugins array in the createAuthClient configuration.

Multi-session plugin adds cookie for multiple sessions

Whenever a user logs in, the multi-session plugin will add an additional cookie to the browser that is used to maintain multiple sessions across different accounts.

listDeviceSessions endpoint lists all active sessions

The listDeviceSessions method is a GET request to /multi-session/list-device-sessions that requires a session. It takes no parameters and lists all active sessions for the current user.

setActive method sets the active session

The setActive method is a POST request to /multi-session/set-active that requires a session. It takes a sessionToken parameter (string) specifying which session token to set as active.

revoke method revokes a specific session

The revoke method is a POST request to /multi-session/revoke that requires a session. It takes a sessionToken parameter (string) specifying which session token to revoke.

signOut revokes all active sessions when user logs out with multi-session enabled

When a user logs out with multi-session enabled, calling the existing signOut method will revoke all active sessions for the user automatically.

maximumSessions option sets limit on concurrent sessions

The maximumSessions option can be passed to the multiSession plugin configuration to specify the maximum number of sessions a user can have. By default, the plugin allows 5 sessions per device.

Multi-session maximumSessions configuration example

To set a custom maximum number of sessions, pass the maximumSessions option to the multiSession plugin: multiSession({ maximumSessions: 3 })

Give your agent this brain

multi-session plugin — Better Auth · Plugins