Baseflare’s permission system is deny-by-default. Every database operation — read, insert, update, and delete — is denied unless a matching rule function explicitly returnsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
true. This means that a table with no entry in your defineRules() call rejects all operations silently, and an operation with a matching rule that returns false or undefined is also denied. There is no implicit “allow all” — every table you intend to access must have rules defined.
defineRules(rules)
defineRules accepts an object mapping table names to a set of rule functions. Each rule function receives a context object with ctx (the function execution context, including ctx.auth) and properties specific to the operation being evaluated.
async. A return value of true grants the operation. Any other return value — false, undefined, or a thrown error — denies it.
Rule Operations
Each table entry can define up to four rule functions, one per operation. All four are optional — omitting a rule for an operation denies it entirely.read
Called once per document on query results. If the rule returns false, that document is silently excluded from the result set rather than returning an error. This applies to .collect(), .first(), .unique(), .take(), .count(), and .paginate(), as well as direct ctx.db.get() lookups.
insert
Called before a document is written by ctx.db.insert(). Returning false rejects the insert and throws a permission error.
update
Called before ctx.db.patch() or ctx.db.replace() is applied. Returning false rejects the write.
delete
Called before ctx.db.delete() removes a document. Returning false rejects the deletion.
ctx.auth.getUserIdentity()
The ctx.auth object is available in every rule function via the ctx property. It exposes getUserIdentity(), which returns the identity value for the current caller (typed as unknown — the auth system is planned and the concrete return type will be finalized when auth ships). The method may return synchronously or as a Promise, so always await it:
getUserIdentity() may return a falsy value (such as null or undefined) when no valid token is present, so rules that require authentication should guard against a falsy identity:
Deny by Default
Allow All (Development)
During local development or prototyping, you may want to bypass permissions entirely. Use rule functions that always returntrue:
Passing Rules to the Worker
Rules are wired into the Worker runtime by passing them tocreateWorker alongside the schema and your function exports: