Skip to main content

OrganizationSwitcher

The OrganizationSwitcher renders an account switcher interface that lets signed-in users switch between their Personal and Organization accounts.

The OrganizationSwitcher renders an account switcher interface that lets signed-in users switch between their Personal and Organization accounts. It displays the , or the user's when no Organization is selected, and provides built-in native controls for managing the Active Organization, switching accounts, accepting Organization invitations and suggestions, and creating an Organization when permitted.

OrganizationSwitcher only renders when a user is signed in and Organizations are enabled for the instance. When Organization selection is required, the Personal Account option is hidden automatically.

OrganizationSwitcher renders the Organization or account trigger only. Render UserButton separately when your layout also needs a profile control.

Note

When Organization selection is required, AuthView automatically handles the choose_organization . Continue rendering AuthView while the session has a pending task, then render your signed-in UI once the task is complete.

  • Name
    displayMode
    Type
    OrganizationSwitcherDisplayMode
    Description

    Controls the trigger style. Defaults to .normal.

    The supported values are:

    • .normal
    • .compact
    • .normal(size:)
    • .compact(size:)

    .normal shows the active account avatar, account name, and disclosure chevron. .compact shows only the avatar-sized account trigger. The default base avatar size is 36 points.

  • Name
    hidePersonal
    Type
    Bool
    Description

    Whether the option should be hidden even when the option is allowed. Defaults to false.

  • Name
    label
    Type
    () -> LabelContent
    Description

    Custom content shown inside the switcher button.

  • Name
    skipInvitationScreen
    Type
    Bool
    Description

    Whether creating an Organization should skip the post-create invitation step. Defaults to false.

Modifiers

Apply the following modifiers to an OrganizationSwitcher to customize the OrganizationProfileView it presents.

  • Name
    organizationProfileDestination(_:)
    Type
    @ViewBuilder (Route) -> some View
    Description

    Builds the view to push when the user selects a custom row. The closure receives the selected row's route.

  • Name
    organizationProfileRows(_:)
    Type
    [OrganizationProfileCustomRow<Route>]
    Description

    Custom rows to show on the root Organization profile screen, alongside Clerk's built-in rows. Rows that share a placement show in array order.

  • Name
    icon
    Type
    OrganizationProfileRowIcon
    Description

    The row's icon. Pass .system(name:) for an SF Symbol, or .asset(name:width:height:) for an image in your app's asset catalog. Clerk renders asset icons as templates, tinted the same color as its built-in row icons, and sizes them 24 × 24 points by default.

  • Name
    placement
    Type
    OrganizationProfileCustomRowPlacement
    Description

    Where to insert the row relative to Clerk's built-in rows:

    • .sectionStart(_:) or .sectionEnd(_:): The start or end of the .profile or .actions section
    • .before(_:) or .after(_:): Before or after a built-in row (.members, .verifiedDomains, .leaveOrganization, or .deleteOrganization)

    Defaults to .sectionEnd(.profile).

    A row placed before or after a built-in row appears only when that built-in row does. .members, .verifiedDomains, and .deleteOrganization depend on the user's Permissions and your instance settings, as listed in Visible rows and Permissions. .leaveOrganization always appears. To always show a row, use .sectionStart(_:) or .sectionEnd(_:).

  • Name
    route
    Type
    Route: Hashable
    Description

    The value passed to organizationProfileDestination(_:), or pushed onto your navigationPath, when the user selects the row.

  • Name
    title
    Type
    LocalizedStringKey | String
    Description

    The row's title.

Usage

The following examples show how to use the OrganizationSwitcher in your app.

Basic usage

import ClerkKit
import ClerkKitUI
import SwiftUI

struct HomeView: View {
  @Environment(Clerk.self) private var clerk

  var body: some View {
    if clerk.user != nil {
      HStack(spacing: 16) {
        OrganizationSwitcher()
        UserButton()
      }
    } else {
      AuthView()
    }
  }
}
OrganizationSwitcher(
  hidePersonal: false,
  displayMode: .compact(size: 40)
)

Custom switcher label

The following example demonstrates how to render a custom switcher label.

import ClerkKitUI
import SwiftUI

OrganizationSwitcher {
  Text("Switch account")
}

Custom rows are shown in the switcher's default OrganizationProfileView only when you provide both .organizationProfileRows() and .organizationProfileDestination().

import ClerkKitUI
import SwiftUI

enum OrganizationRoute: Hashable {
  case settings
}

OrganizationSwitcher()
  .organizationProfileRows([
    .init(
      route: .settings,
      title: "Settings",
      icon: .system(name: "gear"),
      placement: .after(.members)
    ),
  ])
  .organizationProfileDestination { (route: OrganizationRoute) in
    switch route {
    case .settings:
      // Replace this placeholder with the custom view for your Settings row.
      OrganizationSettingsContent()
    }
  }

Feedback

What did you think of this content?

Last updated on