You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// members.collection.tsexportconstMembersCollection: CollectionConfig<'members'>={slug: 'members',auth: true,admin: {useAsTitle: 'email',},access: {create: ({req: { user }})=>Boolean(user?.collection==='users'&&user.roles?.includes('admin')),update: ({req: { user }})=>{// TODO: there is no way to block the payloadcms user only role from editing the auth fields like email and password.returnBoolean(user?.collection==='users')},// TODO: we need something like this to block the payloadcms user only role from updating the auth fields like email and password.// auth: ({ req: { user }}) =>// Boolean(user?.collection === 'users' && user.roles?.includes('admin')),},fields: [{name: 'name',label: 'Name',type: 'text',required: true,},],}
Expected Behavior
The user role from the users collection should not see the auth fields for the member.
The admin role from the users collection should see and be able to update the auth fields for the member.
Current Behavior
There is no field level / auth group level access control specifically for the CRUD actions on the auth fields.
Hey @shiva-hack - sorry if I am misunderstanding your issue but I tested this and using the access.update function does provide the desired behavior that you described:
update: ({req: { user }})=>{constisAdmin=user?.collection==='users'&&user?.roles?.includes('admin')returnisAdmin},
When the user is not an admin, this is how the auth fields would look on the members collection:
They would not be able to edit the email, change the password or force unlock as these get set to read-only.
@JessChowdhury , so this does check the admin key over the entire collection, but what if we just want to disable the auth fields and keep the other fields open?
The user should be able to update other fields except email, change the password or force unlock.
The admin should be able to update all the fields including email, change the password and force unlock.
Describe the Bug
Scenario
members
andusers
.users
collection which has two rolesuser
andadmin
.members
collection has auth fields as well as some extra fields for the member profile.Expected Behavior
user
role from theusers
collection should not see the auth fields for the member.admin
role from theusers
collection should see and be able to update the auth fields for the member.Current Behavior
I have added TODO notes in the members collection
Link to the code that reproduces this issue
https://github.com/shiva-hack/payload/tree/fix/auth-fields-access
Reproduction Steps
Which area(s) are affected? (Select all that apply)
area: ui, area: core
Environment Info
The text was updated successfully, but these errors were encountered: