Access control in kywi.config.ts
Type-level and field-level predicates are functions, so they live only in code — they receive the user and nothing else, and absence always means allowed.
A content type's access block is four optional predicates, and each one is handed the caller and nothing else — no content node, no site id, no request. That constraint is the design, not an oversight: these run before core has decided which row it is dealing with, so they can only ever answer questions about who is asking.
interface AccessControlConfig {
read?: (ctx: { user: UserContext | null }) => boolean
write?: (ctx: { user: UserContext | null }) => boolean
publish?: (ctx: { user: UserContext | null }) => boolean
delete?: (ctx: { user: UserContext | null }) => boolean
}Synchronous, boolean, and independent of each other. A rule that needs
the row it is about — "only the author may edit this page" — is a per-document
permission or a beforeUpdate hook, not one of these.
Absence means allowed
No access block returns true. An access block with no function for the action being attempted returns true. These predicates only ever TIGHTEN: passing one drops the caller into the ordinary role check, so writing write: () => true grants nothing an editor did not already have, and omitting publish while restricting write leaves publishing on the role ladder alone.
defineContentType({
name: 'invoice',
// …
access: {
// Both actions still pass the role check afterwards — this narrows, never widens.
read: ({ user }) => user?.role === 'superAdmin' || user?.groups.includes('finance') === true,
write: ({ user }) => user?.groups.includes('finance') === true,
},
})They are evaluated at the content routes, one call per action: reading a list and reading one node, the three write doors (POST, PUT, PATCH), delete, and both publish routes. A type whose read denies is not filtered out of a listing — the listing route itself refuses, with a 401 for an anonymous caller and a 403 for a signed-in one.
Field-level access is a separate layer
A FieldDefinition carries its own access with read and write, evaluated per key rather than per request. On the way out, denied keys are dropped from the record silently. On the way in, they are a 403 FORBIDDEN_FIELD whose body names the fields the caller tried to change.
How a denied field resolves
What each combination of field definition and predicate does to one key in a create or update payload. The last row is the one that makes the feature usable at all: an admin form posts every field back on every save, so treating a denied field's own stored value as an attempted write would make a read-only field unsaveable for everyone who can see it. Equality is type-aware — dates compare by timestamp, objects by their JSON.
| Name | Type | Default | Description |
|---|---|---|---|
no FieldDefinition | — | allowed | A key with no matching field in the type — |
field with no access | — | allowed | Field-level access is opt-in per field. |
access.read denies | read | dropped | The key is removed from the record the API returns. No error, no marker. |
access.write denies, value changed | write | 403 | The whole request fails with |
access.write denies, value unchanged | write | dropped | An unchanged echo of the stored value is not a write. The key is removed from the UPDATE and the rest of the save proceeds. |
Where these sit relative to per-document permissions
Config predicates gate the TYPE. Per-document permissions gate one node, out of ACL rows in the database, and follow their own rules: superAdmin and siteAdmin bypass them; a node with no rows is open; a node with rows and an anonymous caller is denied. Mutations additionally require read on the node first — you cannot publish or delete something you are not allowed to see. The two layers compose, and neither is a substitute for the other: see Content-level permission overrides for the ACL half and Roles and the capability matrix for the ladder underneath both.
These live only in code
They are functions, so nothing serialises them. The Type Designer cannot express an access predicate, and a type created there has none — which is one of the real differences between a config type and a database type, covered in Config types, Type Designer types, and extension attributes.