Hi everyone,
I'm encountering a peculiar error while working with Payload CMS and its access configuration. Whenever I attempt to access a specific resource, I encounter the following error:
ERROR (payload): NotFound: The requested resource was not found.
at findByID (node_modules\payload\src\collections\operations\findByID.ts:94:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
This error seems to be related to the payload.findByID() function call within my access configuration. I've been troubleshooting this for a while now, and I'm unable to pinpoint the exact cause.
Here's the relevant part of my access configuration code:
import { Access } from 'payload/config'
export const isAdminOrHasTagGroupAccess: Access = async ({
req: { user, payload },
id,
}) => {
if (user) {
if (user.roles.includes('admin')) {
return true
}
const tag = await payload.findByID({
collection: 'tags',
id,
depth: 0,
})
if (tag) {
const tagGroup = await payload.findByID({
collection: 'tag_groups',
id: tag.tag_groups as string,
depth: 0,
})
if (user.tenants?.includes(tagGroup?.tenant as string)) {
return true
}
}
}
return false
}
I've already checked if payload is not null before calling payload.findByID(), and I've ensured that the id being passed is correct.
If anyone has encountered a similar issue or has insights into what might be causing this error, I'd greatly appreciate your input. Thank you!