#Allow access of SOME fields only in auth-enabled collection

5 messages · Page 1 of 1 (latest)

candid narwhal
#

I have a Users collection with auth enabled (with verify). I want to allow access to the username field ONLY to the public. The rest is admin-only.

Right now, I've had to define the collection read access to anyone, and go through every single field except username to add a field-level restriction to restrict access.

Also, I can't restrict access to fields I don't have access to, like _verifyToken or _verify or some other values I might not be aware of.

Is there a better way?

candid narwhal
#

Allow access of SOME fields only in auth-enabled collection

hallow star
#

Not sure if it's useful, but I have a similar situation, where I just needed the name of the users to be available. What I did was make the users collection accessible to admins only. Then, in the collection where I needed that information, I added an auto-populated field, and that field is what's available to users. The strategy is the same one as this from the website template https://github.com/payloadcms/payload/blob/f221f6c22baf28889d7be6dfd96c7fba9e39d612/templates/website/src/collections/Posts/index.ts#L197.

By doing that, I can populate only the user's name (for whatever field I want to).

candid narwhal