Acting As Banner

A sticky bar that says whose account you are acting as, and labels destructive buttons with the org they act on, so support staff don't edit the wrong data.

StopsEdited a customer's data as myself

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/acting-as-banner.json

The files land in your project. They're yours to edit.

Usage

acting-as-banner-usage.tsx
import { ActingAsBanner, OrgContextChip } from "@/components/ui/acting-as-banner"

<ActingAsBanner
  subject={{ name: "Priya Sharma", email: "priya@acme.com" }}
  org="Acme Corp"
  actor="Rahul from Support"
  expiresAt={expiresAt}
  onSwitchBack={() =>
    new Promise<void>((resolve) =>
      setTimeout(() => {
        setActing(false)
        resolve()
      }, 700),
    )
  }
/>

What it catches

  • Forgetting you are impersonating a customer
  • Destructive buttons that don't say which org they act on (via the org chip)
  • Impersonation sessions that have expired
  • A failed switch back, shown as an error

Props

ActingAsBanner props
PropTypeDefault
subject* (required)

The identity whose permissions are in effect right now.

{ name: string; email?: string }—
org

The organization or workspace actions apply to.

string—
actor

Who is really signed in, shown so the session stays accountable.

string—
expiresAt

When the session ends on its own. Shows a live countdown.

Date | string | number—
onExpire

Called once when `expiresAt` passes.

() => void—
onSwitchBack* (required)

Return to your own identity. Return a promise to show a pending state.

() => void | Promise<void>—
sticky

Stick to the top of the scroll container.

booleantrue
actingLabel

Templates: `{name}` and `{minutes}` are filled in.

string"Acting as"
signedInLabel

Text naming who is really signed in.

string"Signed in as {name}"
endsInLabel

Text before the time left in the session.

string"Ends in {minutes} min"
expiredLabel

Text shown when the session has expired.

string"Session expired"
switchBackLabel

Defaults to "Switch back to {actor's first name}".

string—
switchBackErrorText

Shown when switching back fails.

string"Couldn't switch back. Try again."

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • A role="region" with an aria-label naming who you act as and the org
  • Switch-back errors use role="alert"
  • The org colour is decorative; the org is always named in text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Scope impersonation sessions on the server, log every action with both the actor and the subject, and expire sessions server-side.

  • Shows the session you describe in props; it doesn't create or end impersonation
  • The org chip only appears where you add it

What it stops

Edited a customer's data as myself

Also known as

impersonate · login as user · acting as · support mode · org switcher · admin panel · sudo mode · workspace switcher

Field type

Dependencies

Pairs well with