Hello everyone! I'd like to allow the user to have "update" rights only to the articles he has created. I have a simple function that checks if the user pseudonym is equal to the article field but seems I'm doing something wrong because the pseudonym field is undefined.
Perhaps it's possible to somehow pass an article object to this function?
Okay. Seems it doesn't work because the article author is an object
I've updated the code but it gives the same result
You should take at look herehttps://github.com/payloadcms/website-cms/blob/main/src/access/isAdminOrSelf.ts
This part is not working in my case because I have an object and need to compare a key.
hi @mihanc - you can access the full doc using
, take a look at this example:
Why the data can be undefined?
The afterRead hook runs when you save the doc - so if you hit save and check your console.log again you should see the data
Is there any way to access the data before the afterRead hook? I'd like to disable Save button if the user is not the author of this article.
My apologies, you're not using a hook I was mixing this up with another similar thread. However, I would suggest adding a collection hook then you can access the document data before saving with beforeValidate or beforeChangehttps://payloadcms.com/docs/hooks/collections