Configure user access

This commit is contained in:
tobias
2024-05-20 09:10:08 +02:00
parent 1dbb075cd8
commit 1ccf660f5b
3 changed files with 46 additions and 10 deletions

View 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;
}