Multi-tenant workspaces overview
Add multi-tenant workspaces with member management and workspace switching.
Every user can belong to one or more workspaces. Each workspace has its own members, roles, subscription, and data.
import { useSaaSWorkspaces, WorkspaceSwitcher } from '@buildbase/sdk/react';
function Navbar() {
return (
<nav>
<WorkspaceSwitcher
trigger={(isLoading, ws) => (
<button>{ws?.name ?? 'Select workspace'}</button>
)}
/>
</nav>
);
}Note
BuildBase auto-creates a workspace for new users on first login. No setup step required. You choose in the console whether it does, whether people share workspaces or each has one of their own, and who may create workspaces and invite people: see mode and limits.
WorkspaceSwitcher
A drop-in component with search, create, and switch built in. You only provide the trigger button:
| Prop | Type | Description |
|---|---|---|
trigger | (isLoading, currentWorkspace) => ReactNode | Render function for the trigger button |
To react to workspace switches, use the onWorkspaceChange callback in the provider's auth.callbacks - see Workspace Switcher.
useSaaSWorkspaces()
For reading workspace data or managing members programmatically:
| Property / Method | Description |
|---|---|
workspaces | All workspaces the user belongs to |
currentWorkspace | The active workspace |
switchToWorkspace(ws) | Change the active workspace |
createWorkspace(name, image?) | Create a new workspace, with an optional image |
deleteWorkspace(workspaceId) | Delete a workspace (its creator only) |
leaveWorkspace(workspaceId) | Leave a workspace as the signed-in member (anyone but its creator) |
addUser(workspaceId, email, role) | Add an existing account |
inviteMember(workspaceId, email, role) | Invite an address, account or not |
removeUser(workspaceId, userId) | Remove a member |
updateUser(workspaceId, userId, data) | Change a member's role |
getUsers(workspaceId) | List all members |
updateFeature(workspaceId, key, value) | Switch a user-managed workspace feature on or off |
leaveWorkspace is refused with 409 WORKSPACE_OWNER_CANNOT_LEAVE for the workspace's creator, and with 409 PAYER_STILL_PAYS while the workspace's subscription is billed to the member's own card (move its billing to another member or cancel the subscription first). updateFeature is refused with 403 FEATURE_NOT_USER_MANAGED for a flag that is not user managed (Workspace flags).
Workspace names are plain text
A workspace's name is stored as the person typed it: Zoe & Son's <Lab> comes back as those characters from GET /workspaces, useSaaSWorkspaces() and the workspace.* webhook payloads. This is a behaviour change: until this release the server stored a name created or renamed through the API HTML-escaped (Zoe & Son's). React escapes text it renders, so the prebuilt components need nothing; escape the name yourself wherever you put it into HTML, Markdown or a chat message. Names saved before the change keep their stored form until they are renamed.
Pre-built settings
Open the workspace settings panel with one call - handles members, billing, features, and more:
import { useSaaSAuth } from '@buildbase/sdk/react';
function SettingsButton() {
const { openWorkspaceSettings } = useSaaSAuth();
return <button onClick={() => openWorkspaceSettings()}>Settings</button>;
}Every screen it can open, and when each one shows, is in Settings Screens.
Next Steps
- Workspace Switcher - Customizing the trigger.
- Managing Members - Invite users and check seats.
- Invitations - Reach people who have no account yet.
- Settings Screens - All pre-built screens.
- Mode and limits - Personal or Platform, who may create and invite, and member caps.