payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.58k stars 1.5k forks source link

ACL: data and id is undefined when called via local api #7972

Closed Wiz1991 closed 2 weeks ago

Wiz1991 commented 1 month ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.0.0-beta.96
  next: 15.0.0-canary.104
  @payloadcms/db-postgres: 3.0.0-beta.96
  @payloadcms/email-nodemailer: 3.0.0-beta.96
  @payloadcms/graphql: 3.0.0-beta.96
  @payloadcms/next/utilities: 3.0.0-beta.96
  @payloadcms/plugin-redirects: 3.0.0-beta.96
  @payloadcms/plugin-search: 3.0.0-beta.96
  @payloadcms/richtext-lexical: 3.0.0-beta.96
  @payloadcms/richtext-slate: 3.0.0-beta.96
  @payloadcms/translations: 3.0.0-beta.96
  @payloadcms/ui/shared: 3.0.0-beta.96
  react: 19.0.0-rc-fb9a90fa48-20240614
  react-dom: 19.0.0-rc-fb9a90fa48-20240614
Operating System:
  Platform: linux
  Arch: x64
  Version: #202405300957~1721174657~22.04~abb7c06 SMP PREEMPT_DYNAMIC Wed J
  Available memory (MB): 15922
  Available CPU cores: 6

Describe the Bug

Calling findByID() does not populate id and data on read access function. If i do a regular REST API call, the ID only is available.

Reproduction Steps

  1. create a collection with any number of fields
  2. define read access function
  3. log id and data
  4. call payload.findByID()

Adapters and Plugins

No response

r1tsuu commented 2 weeks ago

It's not expected to have data there, since the access function is executed before the document is retrieved from the database (unlike for create/update/delete operations). You need to return a Where query from it.

https://payloadcms.com/docs/access-control/overview#argument-availability

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.