Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeRead and afterRead collection hooks to not modify reponse #7736

Open
mortocks opened this issue Aug 17, 2024 · 2 comments
Open

beforeRead and afterRead collection hooks to not modify reponse #7736

mortocks opened this issue Aug 17, 2024 · 2 comments
Labels
stale status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@mortocks
Copy link

mortocks commented Aug 17, 2024

Link to reproduction

No response

Payload Version

3.0.0-beta.77

Node Version

v20.15.0

Next.js Version

15.0.0-canary.104

Describe the Bug

When you return a value other that the doc from the beforeRead or afterRead collection hooks, the response is not changes.

I suspect this is something to do with the fact that req is not longer one of the args that the hook provides (which is different from what the docs say). Ideally req would still be an argument you get so you can return req.status but failing that, the value you return should be what's returned in the request

Reproduction Steps

  1. Create collection and add to your payload config
export const Article: CollectionConfig = {
  slug: 'article',
  access: {
    read: () => true,
  },
  hooks: {
    beforeRead: [
      ({ req, doc }) => {
        // doesn't work
        return null
      }
    ],
    afterRead: [
      ({ req, doc }) => {
        // doesn't work
        return null
      }
    ]
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    }]
}
  1. Curl for that collection

curl http://localhost:3000/api/article

curl http://localhost:3000/api/article/1

The result will be the document or a collection of documents

Adapters and Plugins

db-postgres

@mortocks mortocks added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Aug 17, 2024
@denolfe denolfe removed the v3 label Nov 19, 2024
Copy link
Contributor

This issue has been marked as stale due to lack of activity.

To keep this issue open, please indicate that it is still relevant in a comment below.

@github-actions github-actions bot added the stale label Dec 13, 2024
Copy link
Contributor

This issue was automatically closed due to lack of activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2024
@denolfe denolfe reopened this Dec 21, 2024
@github-actions github-actions bot removed the stale label Dec 22, 2024
@github-actions github-actions bot added the stale label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants