Payload Access Control Issue

default discord avatar
haniel.u
4 months ago
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
    jarrod69420
    4 months ago

    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.u
    4 months ago

    Still gives the same error

    :pain:
    image.png
  • discord user avatar
    dribbens
    Payload Team
    4 months ago

    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.u
    4 months ago

    Alright let me try



    This works, thank you so much 🥹

  • discord user avatar
    dribbens
    Payload Team
    4 months ago

    You're welcome!

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.