Skip to content

Building a Custom Organization Switcher

Learn how to build your own organization switcher UI for complete control over multi-tenant user experiences.

When users belong to multiple organizations, the default Scalekit organization switcher handles most use cases. However, some applications require deeper integration—a custom switcher embedded directly in your app’s navigation, or a specialized UI that matches your design system.

This guide shows you how to build your own organization switcher using Scalekit’s APIs.

The default Scalekit-hosted switcher works well for most scenarios. Build a custom switcher when you need:

  • In-app navigation: Users switch organizations without leaving your application
  • Custom branding: The switcher matches your application’s design language
  • Specialized workflows: Your app needs org-specific logic during switches
  • Reduced redirects: Avoid sending users through the authentication flow for every switch

Your application handles the entire switching flow:

  1. User authenticates through Scalekit and receives a session
  2. Your app fetches the user’s organizations via the User Sessions API
  3. You render your own organization selector UI
  4. When a user selects an organization, your app updates the active context

This approach gives you full control over the UI and routing, but requires you to manage session state and organization context within your application.

The User Sessions API returns the authenticated_organizations field containing all organizations the user can access. Use this data to populate your switcher UI.

Express.js
// Use case: Get user's organizations for your switcher UI
// Security: Always validate session ownership before returning org data
const session = await scalekit.session.getSession(sessionId);
// Extract organizations from the session response
const organizations = session.authenticated_organizations || [];
// Render your organization switcher with this data
res.json({ organizations });

The response includes organization IDs, names, and metadata for each organization the user can access.

Enhance your switcher by displaying which domains are associated with each organization. Use the Domains API to fetch this information.

// Example: Fetch domains for an organization
const domains = await scalekit.domains.list({ organizationId: 'org_123' });
// Display "@acme.com" next to the organization name in your UI

This helps users quickly identify the correct organization, especially when they belong to organizations with similar names.

When a user selects an organization in your custom switcher, update your application’s context. Store the active organization ID in session storage or a cookie, then use it for subsequent API calls.

Express.js
// Use case: Store selected organization and fetch org-specific data
app.post('/api/select-organization', async (req, res) => {
const { organizationId } = req.body;
const sessionId = req.session.scalekitSessionId;
// Security: Verify the user belongs to this organization
const session = await scalekit.session.getSession(sessionId);
const hasAccess = session.authenticated_organizations.some(
org => org.id === organizationId
);
if (!hasAccess) {
return res.status(403).json({ error: 'Unauthorized' });
}
// Store the active organization in the user's session
req.session.activeOrganizationId = organizationId;
res.json({ success: true });
});

Always verify that the user actually belongs to the organization they’re attempting to switch to. The authenticated_organizations array from the session is your source of truth for access control.

The default Scalekit-hosted switcher is the right choice when:

  • You want the quickest implementation with minimal code
  • Your application doesn’t require in-app organization switching
  • You’re okay with users navigating through the authentication flow to switch organizations

Build a custom switcher when user experience requirements demand deeper integration with your application’s UI and routing.

You may refer to our Sample Org Swithcer application to better understand how the API calls enable this custom org switcher that is embedded inside your application.