Add collections & access functions from paystro
This commit is contained in:
40
src/app/(payload)/collections/Users.ts
Normal file
40
src/app/(payload)/collections/Users.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { CollectionConfig } from 'payload/types'
|
||||
import { isAdmin, isAdminOrSelf } from '@payload/access/isAdmin'
|
||||
|
||||
const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
auth: true,
|
||||
admin: {
|
||||
defaultColumns: ['roles', 'email'],
|
||||
useAsTitle: 'email',
|
||||
},
|
||||
access: {
|
||||
create: isAdmin,
|
||||
read: isAdminOrSelf,
|
||||
update: isAdminOrSelf,
|
||||
delete: isAdmin,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'roles',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: 'Admin', value: 'admin' }, //CRUD, role creation
|
||||
{ label: 'Editor', value: 'editor' }, //CRUD
|
||||
{ label: 'User', value: 'user' }, //cRud, CRUD own entries
|
||||
],
|
||||
required: true,
|
||||
defaultValue: 'user',
|
||||
// JWT so that role is accessible from 'req.user'
|
||||
saveToJWT: true,
|
||||
hasMany: true,
|
||||
access: {
|
||||
create: isAdmin,
|
||||
read: () => true,
|
||||
update: isAdmin,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default Users
|
||||
Reference in New Issue
Block a user