Litestone guide / Access
auth() and claims
auth() is the caller a policy reads. auth().teamId is a claim: a fact the principal carries, and the schema declares which claims exist so a misspelling is refused when the client is built.
model User {
id Int
teamId Int?
}
model Ticket {
id Int (autoincrement())
teamId Int
title String
(0)
(read, teamId == auth().teamId)
}
await db.asSystem().ticket.createMany({ data: [{ teamId: 1, title: 'ours' }, { teamId: 2, title: 'theirs' }] })
const member = db.$setAuth({ id: 1, teamId: 1 })
const nobody = db.$setAuth({ id: 2 })
const mine = await member.ticket.findMany()
const none = await nobody.ticket.findMany()
if (mine.length !== 1 || mine[0].title !== 'ours' || none.length !== 0) throw new Error('claims did not scope the reads')
A caller who does not carry the claim is not "false", they are unknown, and an unknown never satisfies an @@allow.
What else it can do
- The claims a policy may name are the framework's own, the columns of the
@@authmodel, and any declared withclaim claim cartTokenat the top level declares a claim that is on no row, resolved per request by the appclaim contactId bearermarks a claim carried by someone with no account, such as a link holderclaim siteId from Employee(userId).siteIdreads a claim off a row pointing at the caller, on every requestdb.$claimsFor(principal)answers what a principal carries, for a tool or a test@@denyfires on true and on unknown, so a deny naming an absent claim refuses an anonymous callerauth().x == nullis how a policy asks whether the caller carries no such claimauth().levelis the gate's grade for the model being readcreateClient({ claims: [...] })states the same set in code, for a schema you do not own
In depth: Access control § What auth().x may name, § A claim that lives on another row, § An absent claim is UNKNOWN