payload.findByID NotFound error: The request resource was not found

default discord avatar
shisue
last month

Hi,



I'm making a collection access control function and want to check if the user is a manager of the organization being udpated. I am getting the error that findById was not found, despite it working elsewhere and having checks for the req.



The error happens only when I am logging in. If I comment out the code and log in first, and then use it, things work as they should.



import { Access } from "payload/types"; export const isManagerOfOrganizationOrAdmin: Access = async ({ req, id }) => { if (!req || !req.user) return false; if (req?.user?.roles?.includes('admin')) return true; const organization = await req?.payload?.findByID({ collection: 'organizations', id, depth: 0, }); // If the user is a manager of the organization return organization?.managers?.includes(req.user.id); }

export const Organizations: CollectionConfig = { slug: 'organizations', admin: { useAsTitle: 'name', }, access: { create: isAdmin, update: isManagerOfOrganizationOrAdmin, read: () => true, },
    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.