Skip to main content
Back to Next.js

<OrganizationUnitSwitcher />

The OrganizationUnitSwitcher component shows the organization unit the session is in, in a field that opens a menu of the units the signed-in user can access. It reads the units from /users/me/ous through a server action, so the access token stays on the server. Picking a unit calls switchOrganizationUnit from useThunderID(), which signs in again bounded to that unit. A failed switch keeps the session as it was and shows a translated message under the field. For the scenario this component serves, see Switch Organizations.

The component loads the list once the user is signed in. After a switch that completes in place, it calls onSwitch and loads the list again. It renders BaseOrganizationUnitSwitcher from @thunderid/react, so its built-in UI, translation keys, and render props match the React SDK's <OrganizationUnitSwitcher />.

Usage​

Basic Usage​

app/components/Header.tsx
jsx
'use client'
import { OrganizationUnitSwitcher, SignedIn } from '@thunderid/nextjs'

function Header() {
return (
<header>
<SignedIn>
<OrganizationUnitSwitcher scope="siblings" />
</SignedIn>
</header>
)
}

export default Header

Handling the Pick Yourself​

Pass onSelect to take over a pick. The component calls it with the unit instead of switching, so your application decides what happens:

app/components/OrganizationPicker.tsx
jsx
'use client'
import { useRouter } from 'next/navigation'
import { OrganizationUnitSwitcher } from '@thunderid/nextjs'

function OrganizationPicker() {
const router = useRouter()

return <OrganizationUnitSwitcher onSelect={(unit) => router.push(`/orgs/${unit.handle}`)} />
}

export default OrganizationPicker

Props​

PropTypeRequiredDescription
scopeAccessibleOrganizationUnitScope❌'siblings' lists the accessible units that share the parent of the current unit. Omit it to list every accessible unit.
limitnumber❌The page size. Defaults to 10.
onSwitch(unit: AccessibleOrganizationUnit, user: User) => void❌Called with the unit and the refreshed user after a switch that completes in place. A switch that leaves the page completes on the callback instead.
onSelect(unit: AccessibleOrganizationUnit) => void❌Takes over a pick: called with the unit instead of switching.
onError(error: unknown) => void❌Called when a switch or a load fails: with the SDK error for a switch, or with the failed result { success: false, code, statusCode } for a load. The component shows its message either way.
switchOptionsSwitchOrganizationUnitOptions❌Options passed to switchOrganizationUnit. Only redirect applies.
titlestring❌Overrides the small label above the current unit. Pass an empty string to omit it.
classNamestring❌Additional CSS class names.
preferencesPreferences❌Component-level preference overrides, including i18n.
children(props: OrganizationUnitSwitcherRenderProps) => ReactNode❌Render function that replaces the built-in UI. See the render props.

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.