Payload Access Control Issue

default discord avatar
haniel.ulast year
9

Here's a bare minimum reproduction repo:

https://github.com/HanielU/payload-access-control-issue

I've provided screenshots for both My config and errors I'm getting after logging in as a customer



I really have no Idea what I'm doing wrong here...



The logic is basically: Only customers who are in the

recipients

field of a Notification can view that notification

  • default discord avatar
    jarrod69420last year

    Without testing this, I

    think

    this should work:



    return {
      or: [
        {
          and: [
            {
              'recipient.value': {
                equals: user.id,
              },
            },
            {
              'recipient.collection': {
                equals: 'users',
              },
            },
          ]
        },
        {
          and: [
            {
              'recipient.value': {
                equals: user.id,
              },
            },
            {
              'recipient.collection': {
                equals: 'customers',
              },
            },
          ]
        }
      ]
    }
  • default discord avatar
    haniel.ulast year

    Still gives the same error

    :pain:
    image.png
  • discord user avatar
    dribbens
    last year

    Hey @haniel.u try changing your access control to


    return {
        or: [
          {
            'recipient.value': {
              equals: user.id
            }
          },
        ],
      };


    Does that help? Keep the above returns for true/false like you did, but replace line 10 and beyond with this ^

  • default discord avatar
    haniel.ulast year

    Alright let me try



    This works, thank you so much 🥹

  • discord user avatar
    dribbens
    last year

    You're welcome!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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