Skip to content
Discussion options

You must be logged in to vote

@thebergamo the afterRead hook should return a modified document. For reference, here's the types for that hook:

and here are the related docs: https://payloadcms.com/docs/hooks/fields#field-hooks

So your hook should look something like this (not tested):

const afterReadHook: FieldHook<any, string[], any> = async (
  args
): Promise<string[]> => {
  const { doc, req } = args;

  if (req.user?.collection === "users") {
    return doc;
  }

  const media = await payload.find({
    collection: "media",
    where: {
      tags: {
        in: doc.tag.join(","),
      },
    },
  });

  return {
    ...doc

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zubricks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants