feat: enable API key auth on Users collection

This commit is contained in:
Jeffrey 2026-02-25 17:04:58 +01:00
parent 68d6e68cba
commit 82d2e48ee5

View File

@ -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,
},
@ -44,4 +44,4 @@ export const Users: CollectionConfig = {
},
],
timestamps: true,
}
}