Skip to main content
Back to Nuxt

<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 is auto-registered by the Nuxt module.

The component reads the units from GET /api/auth/user/organization-units, a route of the Nuxt module that calls /users/me/ous with the server-held session, so the access token never reaches the browser. Picking a unit calls switchOrganizationUnit, which sends the browser to the sign-in route bounded to that unit. The callback replaces the session only when the sign-in succeeds. For the scenario this component serves, see Switch Organizations.

The component loads the list when it mounts, and loads the first page again when scope or limit changes. It renders BaseOrganizationUnitSwitcher from @thunderid/vue, with the same props, events, and default scoped slot as the Vue SDK's OrganizationUnitSwitcher.

Usage​

Basic Usage​

components/NavBar.vue
vue
<template>
<nav>
<SignedIn>
<OrganizationUnitSwitcher scope="siblings" />
</SignedIn>
</nav>
</template>

Handling the Pick Yourself​

Listen to select (or pass onSelect) to take over a pick. The component calls it with the unit instead of switching, so your application decides what happens:

components/OrganizationPicker.vue
vue
<template>
<OrganizationUnitSwitcher @select="(unit) => navigateTo(`/orgs/${unit.handle}`)" />
</template>

Custom Rendering​

Use the default scoped slot to replace the built-in UI. It receives the slot props, and the component keeps the loading, paging, and switching:

components/OrganizationSelect.vue
vue
<template>
<OrganizationUnitSwitcher>
<template #default="{ organizationUnits, current, onSwitch, switchingId, error }">
<select
:value="current ?? ''"
:disabled="switchingId !== null"
@change="onSwitch(organizationUnits.find((unit) => unit.id === $event.target.value))"
>
<option v-for="unit in organizationUnits" :key="unit.id" :value="unit.id">
{{ unit.name }}
</option>
</select>
<p v-if="error" role="alert">{{ error }}</p>
</template>
</OrganizationUnitSwitcher>
</template>

Built-in UI​

The built-in UI is a field that shows a small label, Organization by default, above the name of the current unit. Clicking the field opens a menu that lists each unit by name and handle, with a check mark on the current unit. The arrow keys open the menu and move through it, Home and End jump to the first and last unit, and Escape closes it. When the listing has more units than limit, the menu shows Previous and Next buttons. While a switch runs, the field shows a spinner and cannot be opened. Picking the current unit does nothing.

The labels and messages use the organization_unit.switcher.* translation keys, the same as in the Vue SDK. A list that fails to load shows The organization units could not be loaded.

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.
onSelect(unit: AccessibleOrganizationUnit) => void❌Takes over a pick: called with the unit instead of switching. Also available as @select.
titlestring❌Overrides the small label above the current unit. Pass an empty string to omit it.
classNamestring❌Extra CSS class added to the root element.
preferencesPreferences❌Component-level preferences, for example i18n.bundles overrides.

Events​

EventDescription
switchEmitted with the unit after switchOrganizationUnit resolves.

Slot Props​

The default scoped slot receives OrganizationUnitSwitcherRenderProps:

PropTypeDescription
organizationUnitsAccessibleOrganizationUnit[]The units of the current page, each with id, handle, name, and an optional logoUrl.
currentstring | nullThe ID of the unit the session is in, or null when it is not known.
currentNamestring | nullThe name of the current unit when the page lists it, or null.
onSwitch(unit: AccessibleOrganizationUnit) => voidSwitches to the unit, or hands it to onSelect. Does nothing for the current unit or while a switch runs.
switchingIdstring | nullThe ID of the unit a switch is in progress to, or null.
isLoadingbooleanWhether the units are loading.
errorstring | nullA translated message for the last failure, or null.
limitnumberThe page size.
offsetnumberThe zero-based offset of the page.
totalResultsnumberThe number of units the listing matches.
onPageChange(offset: number) => voidLoads the page that starts at offset.

GET /api/auth/user/organization-units​

The route that lists the units. It takes the optional query parameters scope (siblings), limit, and offset, and returns one page: current, organizationUnits, totalResults, startIndex, and count. It answers 401 for an invalid or expired session and 400 for a malformed query. When ThunderID rejects the request, the route keeps that status.

<BaseOrganizationUnitSwitcher />​

The Nuxt module also auto-registers BaseOrganizationUnitSwitcher from @thunderid/vue, the presentational picker that OrganizationUnitSwitcher renders. It holds no data of its own, so pass it the units and handle switch and page-change. Its props are listed in the Vue SDK reference.

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.