Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Can Payload CMS support a multi-tenant Next.js application?

default discord avatar
rjzheng8 months ago
10

We've built a MongoDB backed multi-tenant Next.js app where the domain of the web app will determine what project to load. Will Payload CMS be able to support this type of architecture? When we create content, we'll want to store them with an extra field

project: ObjectId

to correlate to the correct project.



Thanks guys, this looks great!

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Yeah it can! Actually working on a client project doing multi tenant right now. In our case we have authors for content, and they are assigned (many) orgs. When they login we use an afterLogin hook (auth collection hook) to check the req.headers.host, that determines what org they are trying to login to by doing a lookup on orgs. Orgs have an array field with domains on it, so that’s what we are looking for, then we set a field on the user i.e. lastLoggedInOrg, and we use that field when they create content, assigning that org id to the content. In your case, projects are orgs.



    I may have missed a couple things, but that’s the gist. Then we lock the collections down by the user and the org they are assigned to. When fetching public data from a frontend you will have to specify an org/project in that query

  • discord user avatar
    jmikrut
    2 years ago

    Also, i made a video about access control where we go through a high-level multi-tenant setup using

    sites

    as a tenant differentiator



    https://www.youtube.com/watch?v=DoPLyXG26Dg
  • discord user avatar
    jacobsfletch
    last year

    We now have an official multi-tenant example! Check it out:

    https://github.com/payloadcms/payload/tree/master/examples/multi-tenant

    For this you’d probably set up a new field on your tenants, like “features” or similar. This could be a list checkboxes to toggle various features on and off, such as blocks. Then in your pages config, you’d write conditional logic into each block to check against the tenants feature list, and if not found, hide the block.



    The tenants collection can lock down the feature list to super-admins only, so tenants can not make changes to their own feature set.

  • default discord avatar
    techinvertedlast year
    @808734492645785600

    I want different clients to have access to different blocks which I as a super-admin can enable and disable. How would I go about building this? Any advice would be much appreciated

  • default discord avatar
    skuhns_last year
    @808734492645785600

    following up on this - is it possible to white label the admin UI based on the tenant of the signed in admin?



    I've followed the multi-tenant guide, but it doesn't cover the branding of the admin UI



    is the best way to fetch data directly in the graphics/Logo component?

  • default discord avatar
    herb3763last year

    ^ Would love some info on this too



    Thanks for the information

    @858693520012476436

    and

    @1090615594568667286

    👍

  • default discord avatar
    brianjmlast year

    Yes, a custom component for

    Icon

    and

    Logo

    would serve your purpose.



    What I don't think you can do is dynamically white label the

    meta

    information like the

    favicon

    (I may be wrong).

  • default discord avatar
    paulpopuslast year

    Exactly as Brian mentioned

    https://payloadcms.com/docs/admin/components

    here you can see all the components you can override, so you could have a logo component that does a fetch or uses a react hook to get the info about the user and render different things



    @354357153366016002

    as well

  • default discord avatar
    jabadabadoot10 months ago

    Hello all, I'm following the multi-tenant example -

    https://github.com/payloadcms/payload/tree/main/examples/multi-tenant

    - and its great what level of access control Payload delivers from the content creator point of view.


    This may not be strictly Payload-related, but in my case I'd like to differentiate the content non-authenticated users/readers are being returned with, based on the domain they came from. I added Next support to your example as other examples do, but it seems to me that's not possible to get the different SSG content to be returned for

    abc.localhost:3000

    and

    bbc.localhost:3000

    without either:


    1) reverse-proxying to

    localhost:3000/abc-home

    and

    localhost:3000/bbc-home

    respectively, plus

    cors: []

    in the Payload config


    2) breaking SSG and using Next's

    usePathname

    hook in the client component



    Am I getting this right?



    no worries, I solved it already w/ good ol'

    https://nextjs.org/docs/pages/building-your-application/routing/middleware
  • discord user avatar
    seanzubrickas
    10 months ago

    Hey

    @769450836660977695

    I'd suggest opening a separate community help thread for this as this one has been solved. Thanks!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.