Hi. In the scenario I develop and sell 1-3 websites themes (Nextjs, Payload) to > 20 clients. Can I use a monorepo that contains all of the clients and can I deploy to Payload Cloud Pro and have the clients configure their DNS settings to point to the server? I have no experience with any of this, open to any suggestions that simplify the process.
The objective will be to scale to over 100 clients, so ideally the development caters to that from the start.
Any search terms you recommend for learning?
Totally! You can achieve multi-tenancy in Payload using role-based access control. There are many topics around this, a quick search using those keywords should get you pretty far. Essentially, you'd have an
organizations
or similar collection for each of your clients. Then, every piece of content is assigned to an organization using a basic relationship field. This way each time a request is made for content you check the content ownership and control access based on whether the user is a pat of that organization. Here are the docs around access control:
https://payloadcms.com/docs/access-control/overview. In your case though, you may want to take this a step further so that your access control also checks domain origins off the request.
As of today the "pro" plan only supports up to three custom domains, though. But you'll still be able to achieve your multi-tenancy setup just the same with the only exception being that the API url won't be unique across each client.
Thanks Jacob. In my case I want to create multiple themes for multiple tenants to select. These tenants have an existing domain, such as JohnDoe.com. Can they configure their DNS settings to point to the Payload server so they can keep their domain name? Does that require setting up a custom domain for each tenant via Payload to link to?
If their front-end is hosted elsewhere like Vercel, Netlify etc, you'd simply point their APIs to your single Payload server.
Ok great, thanks Jacob.
Hi @jacobsfletch . Can you please expand more on the setup. So I'd like to offer portfolio themes that the user can customize to their preferences, such as adding their portfolio items. Themes and layout blocks will initially be unchangeable - they can only select different themes for different styles and edit the content.
How might it work if there's only 1 server? Ideally I'd like to create auth to register them as a client with their name, which will then setup their own database, within my admin database that hosts all of the tenants?
I'm new to backend and only a few months in on front-end - trying to understand the logic to enable an automated system with little to no manual interference.
On a side topic - What boilerplate setup should I use for this project?
The database would be shared amongst the tenants with access control keeping the information separate. If it's a requirement to keep your client's data isolated than multi-tenancy might not be the right choice here. But there are many advantages to multi-tenancy, including simplifying your codebase and infrastructure. You could start off with the basic website template, it's not multi-tenancy but comes with basic role-based access control to get you up and running
https://github.com/payloadcms/template-website. I'm going to be writing better docs for that template today so keep an eye out also.
One thing we definitely should do is make an official multi-tenancy example. This would be huge.
Thanks @jacobsfletch . Yea, that'll be great. I wonder what a popular topic is.... maybe e-commerce, so people can create marketplaces for strange niches, like renting out their swimming pool (that's actually a thing). Maybe you guys can do it using the snowplow app TRBL built.
I'll start off with the template and create the website as stand-alone and develop the multi-tenancy website if I get sales.
With the little bit of knowledge I have, I don't understand how I setup the users to have their own dashboard if they don't have their own URL and I can't access their domain? "To access their dashboard, the tenant simply navigates to their designated subdomain or URL and logs in with their username and password." Should they access my admin panel, register there as a tenant and that'll setup their own database to edit? I'll study that template now.
Either way, the URL is just a mask for your single instance of Payload. When users arrive, access control will determine what they can and cannot see and do. This can be based on user roles, website domains, etc. But the idea is that you have
onerunning Payload server hosting
multipletenants.
Makes sense, thanks Jacob.
The official multi-tenant example has arrived! Check it out:
https://github.com/payloadcms/payload/tree/master/examples/multi-tenantHey @jacobsfletch, thanks for the work on and guide for this! If you could clarify how the domains are supposed to function in production I'd be appreciative. In development it all makes sense to me because it's just on
localhost:3000
, and we are explicitly setting the domain to
abc.localhost.com:3000
But in production I get confused. Suppose I have my domain
project.com
pointed to
project.payloadcms.app
, what do I need to do to get
abc
to login at
abc.project.com/admin
or even
abc.com/admin
? Thank you!
Hey teddy maybe i can help since i been playing around with multi-tenants aswell
In the tenants collection there is a domain array you can add
that says what domains belong to what tenants
you obiously need to set the DNS with whatever provider you use (cloudflare, google, square, etc) to point to your payload server.
Thanks for the info @Headless . I haven't taken it as far as changing DNS yet because I wanted to make sure I first understood how to define a tenant at a subdomain
abc.project.com
. Or even
abc.project.payloadcms.app
. I don't seem to be able to accomplish a setup similar to the localhost subdomain setup from development.
As far as changing DNS records for my Tenant's domain, I imagine it would be accomplished the same way I mapped my
project.com
via A record pointing to a given IP or
app.project.com
pointing to
project.payloadcms.app
?
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.