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 type { CollectionConfig } from 'payload'
|
||||||
import { authenticated } from '../../access/authenticated'
|
import { authenticated } from '../../access/authenticated'
|
||||||
|
|
||||||
// Only admins can manage users
|
|
||||||
const adminOnly = ({ req: { user } }: any) => user?.role === 'admin'
|
const adminOnly = ({ req: { user } }: any) => user?.role === 'admin'
|
||||||
|
|
||||||
export const Users: CollectionConfig = {
|
export const Users: CollectionConfig = {
|
||||||
@ -11,13 +10,15 @@ export const Users: CollectionConfig = {
|
|||||||
create: adminOnly,
|
create: adminOnly,
|
||||||
delete: adminOnly,
|
delete: adminOnly,
|
||||||
read: authenticated,
|
read: authenticated,
|
||||||
update: authenticated, // users can update themselves; field-level locks the role field
|
update: authenticated,
|
||||||
},
|
},
|
||||||
admin: {
|
admin: {
|
||||||
defaultColumns: ['name', 'email', 'role'],
|
defaultColumns: ['name', 'email', 'role'],
|
||||||
useAsTitle: 'name',
|
useAsTitle: 'name',
|
||||||
},
|
},
|
||||||
auth: true,
|
auth: {
|
||||||
|
useAPIKey: true,
|
||||||
|
},
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
@ -34,7 +35,6 @@ export const Users: CollectionConfig = {
|
|||||||
{ label: 'Admin', value: 'admin' },
|
{ label: 'Admin', value: 'admin' },
|
||||||
{ label: 'Redaktör', value: 'editor' },
|
{ label: 'Redaktör', value: 'editor' },
|
||||||
],
|
],
|
||||||
// Only admins can change roles
|
|
||||||
access: {
|
access: {
|
||||||
update: adminOnly,
|
update: adminOnly,
|
||||||
},
|
},
|
||||||
@ -44,4 +44,4 @@ export const Users: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user