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';
|
import { CollectionConfig } from 'payload/types';
|
||||||
|
|
||||||
|
const isAdmin = ({ req: { user } }) => (user && user.role === 'admin');
|
||||||
|
|
||||||
const Users: CollectionConfig = {
|
const Users: CollectionConfig = {
|
||||||
slug: 'users',
|
slug: 'users',
|
||||||
auth: true,
|
auth: true,
|
||||||
@ -7,10 +9,29 @@ const Users: CollectionConfig = {
|
|||||||
useAsTitle: 'email',
|
useAsTitle: 'email',
|
||||||
},
|
},
|
||||||
access: {
|
access: {
|
||||||
read: () => true,
|
read: isAdmin,
|
||||||
},
|
},
|
||||||
fields: [
|
fields: [
|
||||||
// Email added by default
|
{
|
||||||
|
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',
|
name: 'name',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
Loading…
Reference in New Issue
Block a user