Multi-client setup for multi-tenancy with separate studios in Sanity
There are two ways to do this:
- One project, one workspace per client. A single Studio has a workspace for each client, and each workspace's
hiddencallback hides it from users who don't belong to that client. - One project per client. Each client gets a separate Sanity project with its own Studio deployment. This gives full separation.
hidden only changes what a user sees in the Studio. It doesn't control who can read or write the data. Pick based on how strict the isolation has to be and which plan you're on.
Option 1: one Studio, workspaces hidden per user
Pass an array to defineConfig. Each workspace gets its own dataset, name, basePath and schema (Workspaces). Give each one a hidden callback. It receives {currentUser}, and when it returns true the workspace is removed from the workspace menu and chooser. Opening its URL directly shows a not-found screen.
// sanity.config.ts
import {defineConfig} from 'sanity'
const hideUnlessRole = (roleName: string) => ({currentUser}: {currentUser: any}) => {
// currentUser is null before login; returning true also hides it from unauthenticated users
if (currentUser === null) return true
return !currentUser.roles.some((role: {name: string}) => role.name === roleName)
}
export default defineConfig([
{
name: 'client-a',
title: 'Client A',
basePath: '/client-a',
projectId: '<projectId>',
dataset: 'client_a',
hidden: hideUnlessRole('client-a-editor'),
// plugins, schema ...
},
{
name: 'client-b',
title: 'Client B',
basePath: '/client-b',
projectId: '<projectId>',
dataset: 'client_b',
hidden: hideUnlessRole('client-b-editor'),
// plugins, schema ...
},
])Things to know:
- Until authentication resolves, workspaces hidden by a callback are treated as visible and the Studio shows a loading screen.
- This only affects the UI. Anyone with API access can still read data their role allows. To restrict each client to their own dataset, make the datasets private and give members custom roles scoped to their dataset(s) (multi-tenancy guide).
- Plan limits (pricing):
- Custom roles and access control are Enterprise only.
- Private datasets need Growth or Enterprise.
- Free and Growth include 2 datasets. On Growth, extra datasets are a paid add-on.
- Admin-level members of a shared project can reach all project settings, including tokens and webhooks. Give client users content-only roles.
Option 2: a separate project per client
The multi-tenancy guide says multiple projects give complete separation of members and configuration. The trade-offs: you can't reference content across projects, and shared settings have to be duplicated by hand. This is the cleaner choice when each client's editors and frontend are fully separate, and it doesn't depend on Enterprise roles.
You can still keep one codebase and set the project per deployment with environment variables:
// sanity.config.ts
import {defineConfig} from 'sanity'
export default defineConfig({
projectId: process.env.SANITY_STUDIO_PROJECT_ID!,
dataset: process.env.SANITY_STUDIO_DATASET || 'production',
// plugins, schema ...
})Deploy one Studio per client, either Sanity-hosted or self-hosted. On the frontend, create a @sanity/client instance for each tenant with that tenant's projectId, dataset and an explicit apiVersion.
Which to choose
- If clients just shouldn't see each other's Studio and you're on Enterprise (or can accept UI-only separation), use Option 1 with
hidden, plus custom roles and private datasets for real access control. - If you need strict isolation without Enterprise roles, or the per-client dataset count goes past your plan, use Option 2: separate projects.
Show original thread3 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.