I am having a case where I have multiple users (for example Admin, Chef & Customers). The admin can see both the Chef and the Customers users, while the Chef can only see the customers.
I need to give the Chef the ability to create users with roles
customers
only. Currently using the
select
field, the options shown are
Admin
,
Chef
and
Customers
- but I only want to limit the Chef account to see
Customers
option only. How can I achieve that?
const Users: CollectionConfig = {
slug: 'users',
auth: true,
admin: {
useAsTitle: 'email',
},
labels: {
plural: 'Admins',
singular: 'Admin',
},
access: {
read: isAuth,
update: isAuth,
delete: isAuth,
create: isAuth,
},
fields: [
{
name: 'name',
type: 'text',
},
{
name: 'role',
type: 'select',
options: [
// how to filter here based on roles?
{ label: 'Admin', value: ROLES.ADMIN },
{ label: 'Chef', value: ROLES.CHEF },
{ label: 'Customer', value: ROLES.CUSTOMER },
],
required: true,
defaultValue: ROLES.CUSTOMER,
},
],
};
export default Users;
Hello @loaialsharee - this is a common use-case for select fields. There is a role-based example in the Select field documentation
https://payloadcms.com/docs/fields/select
https://payloadcms.com/docs/fields/select#customization
Hi @notchr - That was pretty straight forward! Thanks a lot for the guidance!
Of course!
Good luck 😄
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.