Account Switch Guard

Account Switch Guard is a copy-paste React component that stops posted from the wrong account before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/account-switch-guard
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsPosted from the wrong account

Was this component page useful?

How do I install Account Switch Guard?

pnpm dlx shadcn@latest add @bollard/account-switch-guard

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

What input mistakes does Account Switch Guard catch?

  • An account switch made in another tab of the same browser (BroadcastChannel, with a storage-event fallback)
  • The page's account differing from the most recently active account
  • Ambiguous action buttons, by naming the acting account on the button
  • Rejected actions, with a safe visible retry message

What props does Account Switch Guard accept?

AccountSwitchGuard props
PropTypeDefault
accounts* (required)

Every account signed in on this browser, most recently used first.

GuardAccount[]—
pageAccountId* (required)

The account this page was loaded as. Its data is what the user is looking at.

string—
activeAccountId

Controlled active account. Omit to follow `announceActiveAccount` across tabs.

string—
channel

Channel shared with `announceActiveAccount`.

stringDEFAULT_CHANNEL
onAction* (required)

Runs the action. Receives the page's account id: scope the request to it, not to the session cookie.

(accountId: string) => void | Promise<void>—
onSwitchPage

Reloads this page as the newly active account. Hidden when omitted.

(accountId: string) => void—
identityText

Identity line. `{account}` and `{other}` are filled in.

string"Posting as {account}"
notText

Shown after the identity, naming the account most easily confused with it.

string"not {other}"
switchedText

Warning when another tab switched accounts. `{active}` and `{account}` are filled in.

string"You switched to {active} in another tab. This page still…
actionLabel

Button text for the action when the accounts match.

string"Post"
explicitActionLabel

Action label while the accounts disagree, so the click names its account.

string"Post as {account}"
switchPageLabel

Text for the button that switches the page to the newly active account.

string"Open as {active}"
actionFailedText

Safe, visible message shown when the action callback rejects.

string"That action didn't go through. Check your connection and…

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

How is Account Switch Guard accessible?

  • Mismatch notice sits in an aria-live="polite" region
  • The action button is described by the identity line via aria-describedby
  • The highlight animation is skipped when prefers-reduced-motion is set
  • Avatar colour is decorative (aria-hidden); the account is always named in text

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

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: The server must act as the account the session actually authenticates, and reject requests whose stated account differs from it.

  • Only sees switches reported through its own channel; switches made elsewhere (another browser, device or app) are invisible
  • It does not change which session the request is sent with; your onAction decides that

What expensive mistakes does Account Switch Guard stop?

Posted from the wrong account

Also known as

account switcher · multiple accounts · posting as · brand account · google account · workspace · profile switch · multi-login

Field type

What dependencies does Account Switch Guard require?

Account Switch Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameAccount Switch Guard
Registry identifier@bollard/account-switch-guard
Install commandnpx shadcn@latest add @bollard/account-switch-guard
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-11-15
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Account Switch Guard

What form validation mistake does Account Switch Guard catch?

Account Switch Guard prevents posted from the wrong account. Names which account an action runs as, and notices when another tab switched accounts, so nobody posts from the wrong one. Catches: An account switch made in another tab of the same browser (BroadcastChannel, with a storage-event fallback), The page's account differing from the most recently active account, Ambiguous action buttons, by naming the acting account on the button, Rejected actions, with a safe visible retry message. Limitation: validate account-switch-guard schemas on backend.

How do I install account-switch-guard with shadcn?

Run `npx shadcn@latest add @bollard/account-switch-guard`. Sources added: registry/default/account-switch-guard/account-switch-guard.tsx. Package requirements: lucide-react.

What props customize Account Switch Guard?

Account Switch Guard accepts `accounts`, `pageAccountId`, `activeAccountId`, `channel`, `onAction`. Configures account switcher, multiple accounts, posting as behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of account-switch-guard?

Only sees switches reported through its own channel; switches made elsewhere (another browser, device or app) are invisible. It does not change which session the request is sent with; your onAction decides that Server requirement: The server must act as the account the session actually authenticates, and reject requests whose stated account differs from it.

How does Account Switch Guard meet accessibility guidelines?

Mismatch notice sits in an aria-live="polite" region. The action button is described by the identity line via aria-describedby. The highlight animation is skipped when prefers-reduced-motion is set. Avatar colour is decorative (aria-hidden); the account is always named in text. Minimizes errors: posted from company account by mistake, wrong google account.

Which components pair with Account Switch Guard?