generated from autonomic-cooperative/astro-payload-template
Restrict user collection to admins
This commit is contained in:
parent
40d257a0eb
commit
f017fa28dc
@ -1,5 +1,7 @@
|
||||
import { CollectionConfig } from 'payload/types';
|
||||
|
||||
const isAdmin = ({ req: { user } }) => (user && user.role === 'admin');
|
||||
|
||||
const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
auth: true,
|
||||
@ -7,10 +9,29 @@ const Users: CollectionConfig = {
|
||||
useAsTitle: 'email',
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
read: isAdmin,
|
||||
},
|
||||
fields: [
|
||||
// Email added by default
|
||||
fields: [
|
||||
{
|
||||
name: 'role',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: 'ssg', value: 'ssg' }, //cRud
|
||||
{ label: 'Admin', value: 'admin' }, //CRUD, role creation
|
||||
{ label: 'Editor', value: 'editor' }, //CRUD
|
||||
{ label: 'User', value: 'user' }, //CRUd
|
||||
],
|
||||
required: true,
|
||||
defaultValue: "user",
|
||||
access: {
|
||||
create: isAdmin,
|
||||
read: isAdmin,
|
||||
update: isAdmin,
|
||||
},
|
||||
admin: {
|
||||
readOnly: !isAdmin
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
|
Loading…
Reference in New Issue
Block a user