Multi Session
better-auth-ui/multi-sessionFreeComponent
Multi-session plugin: Enable multiple concurrent sessions with account switching. Registers account management cards in account settings and a switch account submenu in the user button.
Live preview
live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://better-auth-ui.com/r/multi-session.jsonSource
1"use client"23import {4 type MultiSessionAuthClient,5 useAuth,6 useAuthPlugin,7 useListDeviceSessions,8 useSession9} from "@better-auth-ui/react"10import { Fragment } from "react"1112import { Card, CardContent } from "@/components/ui/card"13import { ItemGroup, ItemSeparator } from "@/components/ui/item"14import { multiSessionPlugin } from "@/lib/auth/multi-session-plugin"15import { cn } from "@/lib/utils"16import { ManageAccount } from "./manage-account"1718export type ManageAccountsProps = {19 className?: string20}2122/**23 * Render a card that lists and manages all device sessions for the current user.24 *25 * Shows each session with user information and actions to switch to or revoke a session.26 * When device session data is loading, a pending placeholder row is displayed.27 *28 * @returns A JSX element containing the accounts management card29 */30export function ManageAccounts({ className }: ManageAccountsProps) {31 const { authClient } = useAuth()32 const { localization: multiSessionLocalization } =33 useAuthPlugin(multiSessionPlugin)34 const { data: session } = useSession(authClient)3536 const { data: deviceSessions, isPending } = useListDeviceSessions(37 authClient as MultiSessionAuthClient38 )3940 const otherSessions = deviceSessions?.filter(41 (deviceSession) => deviceSession.session.id !== session?.session.id42 )4344 const allRows = [45 {46 key: session?.session.id ?? "current",47 deviceSession: !isPending ? session : null,48 isPending49 },50 ...(otherSessions?.map((deviceSession) => ({51 key: deviceSession.session.id,52 deviceSession,53 isPending: false54 })) ?? [])55 ]5657 return (58 <div>59 <h2 className="text-sm font-semibold mb-3">60 {multiSessionLocalization.manageAccounts}61 </h2>6263 <Card className={cn("p-0", className)}>64 <CardContent className="p-0">65 <ItemGroup className="gap-0">66 {allRows.map((row, index) => (67 <Fragment key={row.key}>68 {index > 0 && <ItemSeparator />}69 <ManageAccount70 deviceSession={row.deviceSession}71 isPending={row.isPending}72 />73 </Fragment>74 ))}75 </ItemGroup>76 </CardContent>77 </Card>78 </div>79 )80}
What it pulls in
npm packages
Other registry items
Files it writes
More from better-auth-ui
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Account Settingsaccount-settings | better-auth-ui | Components | Free | 2 deps | |
| Active Sessionsactive-sessions | better-auth-ui | Components | Free | 5 deps · 2 files | |
| Additional Fieldadditional-field | better-auth-ui | Components | Free | 5 deps | |
| Adminadmin | better-auth-ui | Components | Free | 4 deps · 3 files | |
| Anonymousanonymous | better-auth-ui | Components | Free | 4 deps · 3 files | |
| API Keyapi-key | better-auth-ui | Components | Free | 4 deps · 10 files | |
| Authauth | better-auth-ui | Components | Free | 2 deps | |
| Auth Providerauth-provider | better-auth-ui | Components | Free | 4 deps · 2 files |
