How can I do
req.user.roles.some((role)=>roles.includes(role))to restrict access to a collection ?
Definition of roles field
{
name: 'roles',
type: 'select',
options: [
//...
],
hasMany: true,
}How can i do
req.user.roles.some((role)=>roles.includes(role))in collection access
I do....
export const isSuperAdmin: Access<
any, // eslint-disable-line @typescript-eslint/no-explicit-any
Admin
> = ({ req: { user } }) => {
return Boolean(user?.role.includes('superAdmin'));
};and an example of it on a collection
access: {
read: () => true,
create: isUserAdmin,
update: isUserAdmin,
delete: isUserAdmin,
admin: ({ req: { user } }) => {
return (
user.role.includes('userAdmin') || user.role.includes('superAdmin')
);
},
},either as an imported fn, or written out
is it possible with query only ?
hmm wdym by query only?
I already do it like that, but it's not great because I often have to mix a Drizzle query with post-processing in the then
Can you give an example of that?
something like this but obviously it dont work because access_right.roles is an array
Thank you for replying to me once again

Star
Discord
online
Get dedicated engineering support directly from the Payload team.