Workspace Switcher
Drop-in workspace selector with search, create, and switch built in.
WorkspaceSwitcher is a render-prop component. You provide the trigger UI, and BuildBase opens the Switch Workspace dialog with search, create, and switch built in.
import { useSaaSWorkspaces, WorkspaceSwitcher } from '@buildbase/sdk/react';
function Navbar() {
const { currentWorkspace } = useSaaSWorkspaces();
return (
<nav className="flex h-14 items-center justify-between border-b px-4">
<div className="flex items-center gap-3">
<Logo />
<WorkspaceSwitcher
trigger={(isLoading, workspace) => (
<button className="hover:bg-muted flex items-center gap-2 rounded-md px-3 py-1.5">
<span className="font-medium">
{isLoading
? 'Loading...'
: (workspace?.name ?? 'Select workspace')}
</span>
<ChevronDownIcon className="text-muted-foreground h-4 w-4" />
</button>
)}
/>
</div>
<UserMenu />
</nav>
);
}Tip
The WorkspaceSwitcher includes create, search, and switch functionality built in. You only need to provide the trigger button.
Props
| Prop | Type | Description |
|---|---|---|
trigger | (isLoading: boolean, currentWorkspace: IWorkspace | null) => ReactNode | Render function for the trigger element. First param is loading state, second is the active workspace or null. |
How the trigger works
The trigger prop receives two arguments: a boolean isLoading flag and the current workspace object (or null if none is selected). Return any React element - a button, a styled div, an icon. Pressing it opens the switcher dialog.
import { WorkspaceSwitcher } from '@buildbase/sdk/react';
function MinimalSwitcher() {
return (
<WorkspaceSwitcher
trigger={(isLoading, workspace) => (
<button>
{isLoading ? 'Loading...' : (workspace?.name ?? 'No workspace')}
</button>
)}
/>
);
}What's built in
Pressing the trigger opens the Switch Workspace dialog: the current workspace, the others the person can open, a search over them, and Create New Workspace.

Create New Workspace asks for a Workspace Name and an icon, then Create Workspace makes it and switches to it.

Reacting to workspace changes
WorkspaceSwitcher has no change callback. To run code when the user switches workspace, use the onWorkspaceChange callback in the provider's auth.callbacks. It receives { workspace, user, role } and fires before the switch - the switch proceeds only when the returned promise resolves, and rejecting aborts it.
import { ApiVersion, SaaSOSProvider } from '@buildbase/sdk/react';
function AppProvider({ children }) {
return (
<SaaSOSProvider
serverUrl="https://your-server.com"
version={ApiVersion.V1}
orgId="your-org-id"
auth={{
clientId: 'your-client-id',
redirectUrl: 'http://localhost:3000/callback',
callbacks: {
// ...getSession, handleAuthentication, onSignOut
onWorkspaceChange: async ({ workspace, user, role }) => {
// Runs before the switch completes. Throw to abort the switch.
console.log(
`${user?.name} switching to ${workspace.name} as ${role}`
);
},
},
}}
>
{children}
</SaaSOSProvider>
);
}It also fires when the workspace is restored from storage on page refresh. For the required callbacks (getSession, handleAuthentication, onSignOut), see Installation.
Next Steps
- Managing Members - Invite users, assign roles, and manage workspace membership.