Daria
Daria

Reputation: 15

Keystone js 6: How to add access control on id field of a list

I have a problem with adding an access control on an id field of a list, since id field is added automatically when file schema.prisma is added. I want to make an id field with the following access:

access: { read: ()=> true, update: ()=> false }

I tried to find some explanation in keystone 6 docs, but it seems like there's none. Hope somebody could help me.

Upvotes: 1

Views: 500

Answers (1)

Molomby
Molomby

Reputation: 6559

What you're describing is effectively the only behaviour ID fields support. Specifically:

  • You can't restrict read access for ID fields – if a user can read an item, they can always read its ID. The only way to hide the value of item IDs is to use filter-level access control to hide the entire item.
  • You can't (easily) update ID values – they're excluded from the GraphQL input types. I don't know if this is explicitly called out in the docs but you can see it in the examples in the GraphQL overview. This would also be true for the Query API, as it uses the same GraphQL schema under the hood, and I'm pretty sure it's also true for the DB API. (If you did ever want to modify the value of an ID field, you can possibly do it via the Prisma client on context – I'm not completely sure.)

For better or worse, these behaviours can't be overridden. ID fields are just special in this respect – they don't support standard field-level access control.

Upvotes: 0

Related Questions