I need some new ideas. I'm currently getting this error:
⨯ APIError: The collection with slug users can't be found. Find Operation.
at isFirstUser (./src/lib/payload/is-first-user.ts:11:74)
at hasAdminAccessButNotFirstUser (./src/lib/payload/access.ts:23:123)
at async Promise.all (index 1)
at async Promise.all (index 0)
The code with the error:
import { User } from '@/payload-types'
import payload from 'payload'
export default async function isFirstUser(id: User['id'] | undefined) {
if (!id) {
return false
}
const result = await payload.find({
collection: 'users',
depth: 1,
page: 1,
limit: 1,
pagination: false,
sort: '+id',
})
if (result.docs[0].id === id) {
return true
}
return false
}
Again, my goal is to ensure the first user's role can't be changed.
This isn't working because at the first time an account is created, the slugs/database must not be setup yet. Is what I'm asking possible in Payload? I'd hope so.