diff --git a/src/auth/operations/access.ts b/src/auth/operations/access.ts index 40cd096f4e..46f25d1a8f 100644 --- a/src/auth/operations/access.ts +++ b/src/auth/operations/access.ts @@ -78,7 +78,7 @@ async function accessOperation(args: Arguments): Promise { }); }; - const executeEntityPolicies = (entity, operations, type) => { + const executeEntityPolicies = async (entity, operations, type) => { if (!results[type]) results[type] = {}; results[type][entity.slug] = { @@ -99,7 +99,7 @@ async function accessOperation(args: Arguments): Promise { }; if (userCollectionConfig) { - results.canAccessAdmin = userCollectionConfig.access.admin ? userCollectionConfig.access.admin(args) : isLoggedIn; + results.canAccessAdmin = userCollectionConfig.access.admin ? await userCollectionConfig.access.admin(args) : isLoggedIn; } else { results.canAccessAdmin = false; } diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index f9aa0c41b3..4e042b4662 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -236,7 +236,7 @@ export type CollectionConfig = { readVersions?: Access; update?: Access; delete?: Access; - admin?: (args?: any) => boolean; + admin?: (args?: any) => boolean | Promise; unlock?: Access; }; /** diff --git a/test/access-control/config.ts b/test/access-control/config.ts index 8eed5be93a..298ecc16d3 100644 --- a/test/access-control/config.ts +++ b/test/access-control/config.ts @@ -31,7 +31,22 @@ const UseRequestHeadersAccess: FieldAccess = ({ req: { headers } }) => { }; export default buildConfig({ + admin: { + user: 'users' + }, collections: [ + { + slug: 'users', + auth: true, + access: { + // admin: () => true, + admin: async () => new Promise((resolve) => { + // Simulate a request to an external service to determine access, i.e. another instance of Payload + setTimeout(resolve, 50, true); // set to 'true' or 'false' here to simulate the response + }), + }, + fields: [] + }, { slug, access: {