Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhance admin.hidden to support multi-tenant context: pass req and allow async #14264

antonioru started this conversation in Feature Requests & Ideas
Discussion options

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);
 },
 },
};
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /