Skip to content
rw3iss Auth

OrgSwitcher

form @rw3iss/auth-client/preact/forms/OrgSwitcher framework-adapters/preact/components/forms/OrgSwitcher.tsx ↗

Dropdown of the user’s organization memberships with a click-to-switch action. Switching calls AuthClient.switchOrg(orgId) which:

  1. Refreshes the access token with the new organization_id.
  2. Emits the org_switched event for subscribers.
  3. Updates the auth snapshot’s claims so consumers gating UI on claims.org_id react automatically.

The current org is read from the claims; the dropdown highlights it. Membership is verified server-side every switch, so a stale MyOrgRecord from getMyOrgs() won’t grant unauthorized access.

Usage

import { OrgSwitcher } from '@rw3iss/auth-client/preact/forms';
<OrgSwitcher
onError={(err) => console.error(err)}
/>

Props

NameTypeDescription
clientAuthClient
onSwitch(org: MyOrgRecord) => void
onError(err: Error) => void
classNamestring