generated from autonomic-cooperative/astro-payload-template
Configure user access
This commit is contained in:
21
payload/src/access/isAdminOrSelf.ts
Normal file
21
payload/src/access/isAdminOrSelf.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Access } from "payload/config";
|
||||
|
||||
export const isAdminOrSelf: Access = ({ req: { user } }) => {
|
||||
// Need to be logged in
|
||||
if (user) {
|
||||
// If user has role of 'admin'
|
||||
if (user.roles?.includes('admin')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If any other type of user, only provide access to themselves
|
||||
return {
|
||||
id: {
|
||||
equals: user.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reject everyone else
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user