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
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
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.jsonThis copies:
src/lib/auth/admin-plugin.tssrc/components/auth/admin/stop-impersonating.tsx
Register the copied UI plugin
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