BETTER-AUTH. UI
Plugins

Admin

Add a stop-impersonating user menu action to Solid and Zaidan.

The Admin plugin adds a "Stop impersonating" action to the copied <UserButton />. The action appears only while Better Auth marks the current session as an impersonation session.

Setup

Enable the Better Auth admin plugin

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

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

Update your database schema after enabling the plugin. Better Auth adds admin fields to users and an impersonatedBy field to sessions.

Add the matching Solid client plugin

src/lib/auth-client.ts
import { createAuthClient } from "@better-auth-ui/solid"
import { adminClient } from "better-auth/client/plugins"

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

Install the Solid and Zaidan integration

npx shadcn@latest add https://better-auth-ui.com/r/solid/admin.json

This copies:

  • src/lib/auth/admin-plugin.ts
  • src/components/auth/admin/stop-impersonating.tsx

Register the copied UI plugin

src/components/providers.tsx
import { AuthProvider } from "@/components/auth/auth-provider"
import { adminPlugin } from "@/lib/auth/admin-plugin"

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

User button behavior

The copied adminPlugin() contributes <StopImpersonating /> through the userMenuItems slot. <UserButton /> places it above sign out.

The action renders only when session.session.impersonatedBy is present. Selecting it calls authClient.admin.stopImpersonating() and refreshes the cached session before the pending state completes.

import { StopImpersonating } from "@/components/auth/admin/stop-impersonating"

<StopImpersonating />

Prop

Type

Options

adminPlugin({
  localization: {
    stopImpersonating: "Return to admin"
  }
})

Prop

Type

Localization

Prop

Type

Mutation API

import { stopImpersonatingOptions } from "@better-auth-ui/solid"

const stopImpersonating = stopImpersonatingOptions(authClient)

Use the options when you need the same behavior outside the copied user button. They restore the admin session and await invalidation of the shared session query.

See the Solid package reference for the shared query and mutation APIs.

Last updated on

On this page