Hi everyone! đź‘‹
I’m new to Payload CMS and using API-Key auth to fetch my Jobs collection, but I get a permissions error.
Setup so far:
1. Created a user with an API key in the Admin UI.
2. Enabled useAPIKey: true on Users and Jobs.
3. Added a read rule on Jobs that checks Boolean(user) and logs req.user.
4. Set admin.user = Users.slug in payload.config.ts.
// collections/Jobs.ts
export const Jobs: CollectionConfig = {
slug: 'jobs',
auth: { useAPIKey: true },
access: {
read: ({ req: { user } }) => {
console.log('req user:', user)
return Boolean(user)
},
},
// fields…
}
// collections/Users.ts
export const Users: CollectionConfig = {
slug: 'users',
auth: { useAPIKey: true },
// fields…
}
Request:
curl -X GET http://localhost:3001/api/jobs
-H 'authorization: users API-Key 6c9c5ce9-414a-4c5c-b096-de75bd631d71'
Response:
{ "errors": [{ "message": "You are not allowed to perform this action." }] }
Log in hook:
req.user: Request { method: 'GET', url: '…/api/jobs', headers: { authorization: 'users API-Key …' }, … }
Expected:
• req.user populated with the API-Key user object
• Access granted, returning the jobs array
Already tried:
• Restarting server after each change
• Verifying the key is active in Admin
• Hitting /api/users/me with the same header (returns user)
Any ideas what I’m missing? Maybe my auth config, header format, or a Payload bug? Thanks! 🙏