joas8211 / payload-tenancy

Multi-tenancy plugin for Payload CMS
MIT License
150 stars 11 forks source link

How to use with local api (on collections) #21

Closed silveltman closed 1 year ago

silveltman commented 1 year ago

For the new globals feature you added the following explanation in the docs:

To operate on isolated globals using Local API, you must pass user object with a tenant so that the correct document is accessed.

const globalDocument = await payload.findGlobal({
  slug: "settings",
  user: { tenant: someTenantOrId },
});

For regular collection, is adding user: { tenant: someTenantOrId } also the way to go?

joas8211 commented 1 year ago

I think it should be possible to do that. You can also use where conditions with tenant.equals query. If the request is made by user, just pass the original request object to the call. Remember to set overrideAccess to false if you want to have restricted access.