Support session banner
A banner that tells the user a support agent is viewing the app as them, rendered on the server. It loads its data on the server through the block's client.
pnpm dev:example) to see it.Add the components
terminal npx shadcn add alertInstall the glue
Install the block with
npx better-supabase add impersonation. The glue items are copied into your app, so edit them as you need.None: the page calls the block's client on the server.
Write the component
React and shadcn
View in the exampleimpersonation-banner.tsx import { LifeBuoyIcon } from "lucide-react"; import { getExtracted } from "next-intl/server"; import { Alert, AlertAction, AlertDescription, AlertTitle, } from "@/components/ui/alert"; import { ExitSupportButton } from "@/features/support/components/exit-support-button"; import { getSession } from "../user-queries"; // skeleton: renders from props and translations, so nothing of its own suspends /** * Shown during a support session (`bsb.startSupport`): staff see the app as the * user, and the audit log records who acted. Render inside `<Suspense>`. */ export async function ImpersonationBanner() { const [session, t] = await Promise.all([getSession(), getExtracted("user")]); if (session.kind !== "user" || !session.impersonator) { return null; } const { id, reason } = session.impersonator; return ( <Alert variant="destructive" data-testid="impersonation"> <LifeBuoyIcon /> <AlertTitle>{t("Support session")}</AlertTitle> <AlertDescription> {reason ? t("Signed in by support ({id}): {reason}", { id, reason }) : t("Signed in by support ({id}).", { id })} </AlertDescription> <AlertAction> <ExitSupportButton /> </AlertAction> </Alert> ); }