BETTER-AUTH. UI
Plugins

Multi Session

Enable multiple concurrent sessions with account switching. Allow users to sign in to multiple accounts simultaneously and switch between them seamlessly.

The multi-session plugin enables users to maintain multiple active sessions simultaneously. Users can switch between accounts without signing out, manage all their device sessions, and quickly add new accounts from the user menu.

It contributes:

  • A "Switch Account" submenu in the user button dropdown showing all active device sessions
  • A <ManageAccounts /> card in account settings for viewing and revoking device sessions
  • useListDeviceSessions, useSetActiveSession, and useRevokeMultiSession hooks

Setup

Install the Better Auth plugin

Add the Multi Session plugin to your Better Auth server config:

lib/auth.ts
import { betterAuth } from "better-auth"
import { multiSession } from "better-auth/plugins"

export const auth = betterAuth({
  // ...
  plugins: [
    multiSession() 
  ]
})

Install the matching client plugin

Add multiSessionClient() to your auth client so authClient.multiSession.* methods are available:

lib/auth-client.ts
import { createAuthClient } from "better-auth/react"
import { multiSessionClient } from "better-auth/client/plugins"

export const authClient = createAuthClient({
  plugins: [multiSessionClient()] 
})

Register the UI plugin

Pass multiSessionPlugin() to <AuthProvider>:

components/providers.tsx
import { AuthProvider } from "@better-auth-ui/heroui"
import { multiSessionPlugin } from "@better-auth-ui/heroui/plugins"

<AuthProvider
  authClient={authClient}
  navigate={navigate}
  plugins={[multiSessionPlugin()]} 
>
  {children}
</AuthProvider>

Components

<UserButton />

The "Switch Account" submenu is automatically added to the <UserButton /> dropdown when the plugin is registered. It shows all active device sessions and lets users switch between them with one click, add a new account, and see which account is currently active.

Usage

import { SwitchAccountSubmenu } from "@better-auth-ui/heroui/plugins"

<SwitchAccountSubmenu />

Props

Prop

Type

<ManageAccounts />

Manage accounts

The <ManageAccounts /> card is automatically rendered in account settings when the plugin is registered.

Usage

import { ManageAccounts } from "@better-auth-ui/heroui/plugins"

<ManageAccounts />

Props

Prop

Type

Options

multiSessionPlugin({
  // Override any of the plugin's localization strings.
  localization: {
    switchAccount: "Switch Account",
    addAccount: "Add Account",
    manageAccounts: "Manage Accounts"
  }
})

Prop

Type

Localization

Prop

Type

Session management

The plugin provides hooks for managing multiple sessions:

  • useListDeviceSessions - List all device sessions for the current user
  • useSetActiveSession - Switch to a different session
  • useRevokeMultiSession - Sign out from a specific session

Last updated on

On this page