Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
igormfe6 months ago
2

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, },
  • default discord avatar
    Payload-Botlast year


  • default discord avatar
    ashketshup7 months ago

    What did you do to solve?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.