feat: enable API key auth on Users collection
This commit is contained in:
parent
68d6e68cba
commit
82d2e48ee5
@ -1,7 +1,6 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
import { authenticated } from '../../access/authenticated'
|
||||
|
||||
// Only admins can manage users
|
||||
const adminOnly = ({ req: { user } }: any) => user?.role === 'admin'
|
||||
|
||||
export const Users: CollectionConfig = {
|
||||
@ -11,13 +10,15 @@ export const Users: CollectionConfig = {
|
||||
create: adminOnly,
|
||||
delete: adminOnly,
|
||||
read: authenticated,
|
||||
update: authenticated, // users can update themselves; field-level locks the role field
|
||||
update: authenticated,
|
||||
},
|
||||
admin: {
|
||||
defaultColumns: ['name', 'email', 'role'],
|
||||
useAsTitle: 'name',
|
||||
},
|
||||
auth: true,
|
||||
auth: {
|
||||
useAPIKey: true,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'name',
|
||||
@ -34,7 +35,6 @@ export const Users: CollectionConfig = {
|
||||
{ label: 'Admin', value: 'admin' },
|
||||
{ label: 'Redaktör', value: 'editor' },
|
||||
],
|
||||
// Only admins can change roles
|
||||
access: {
|
||||
update: adminOnly,
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user