-
Notifications
You must be signed in to change notification settings - Fork 3k
Enhance admin.hidden to support multi-tenant context: pass req and allow async #14264
-
Hey team,
In multi-tenant setups, when defining a Collection the admin.hidden function only receives the { user } argument, which makes it hard to drive visibility based on the active tenant or other request-scoped data.
A common need is to show or enable a collection only when the user is operating within an allowed tenant.
Without access to the current request, we can’t reliably read the active tenant selection (for example from a multi-tenant plugin) or perform context-aware lookups.
I propose extending admin.hidden so it can optionally receive the req object and support returning a promise, while preserving backward compatibility with the existing synchronous signature.
This would let implementations base visibility on request-scoped tenant info, cookies/headers, or quick async checks, and continue working for simple user-only cases.
Current API:
admin: { hidden: ({ user }) => boolean }
Proposed (backward compatible):
admin: { // still works synchronously hidden: ({ user, req }) => boolean, // or asynchronously for tenant lookups / DB checks hidden: async ({ user, req }) => { const activeTenant = req?.tenantSelection?.tenant; // example return !user?.tenants?.includes(activeTenant?.id); }, }
Example: Hide a collection unless the user selects an active tenant:
export const Orders: CollectionConfig = { slug: 'orders', admin: { hidden: async ({ user, req }) => { const activeTenantId = req?.tenantSelection?.tenant?.id; return !activeTenantId || !user?.tenants?.some(t => t.id === activeTenantId); }, }, };
Beta Was this translation helpful? Give feedback.