Downgrade the plan. The Export button hides itself.
Roles, ownership rules, feature flags and plan tiers behind one reactive function, can(). A rule that reads a signal re-checks when the signal changes, so every button, route and menu that asked follows on its own.
bun add @pyreon/permissions - one call
can('posts.update', post)Rules aretrue,falseor a predicate.- vs CASL 7
- 1.3–1.9× on the resolver raceOne run, bun/JavaScriptCore, author-run. Exact deny ties.
- wildcards
posts.*·posts.**·*Most specific wins, so a deny beats a broad grant.- iOS and Android
-
can,all,anylower to a native runtimeNative targets are experimental.
- 1.3–1.9× faster than CASL when both resolve every checkBENCHMARKS.md §10, permissions row · overnight run, one run, bun/JavaScriptCore
- 3 runtime exports:
createPermissions,PermissionsProvider,usePermissionspackages/fundamentals/permissions/src/index.ts
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →Access rules that keep up with the user.
Rules that read signals re-check by themselves
'posts.update': (post) => (post as Post).authorId === me().id. Switch accounts withme.set(…)and everycan('posts.update', post)on screen re-evaluates. Nothing to rebuild, noability.update(rules).One shape for every model
Role grants are booleans, ownership is a predicate, a feature flag is
() => flags().beta, a plan tier is() => plan() === 'pro'. All of them are string keys you check the same way.Wildcards with a clear winner
billing.**grants the subtree,billing.refunds.**: falsecarves out refunds. Lookups go exact, then*, then**, most specific first, so the deny wins.Fails closed
A predicate that throws, or returns anything other than
true, denies.can.assert()throws[Pyreon] permission denied: 'posts.delete'for loaders and server actions.
Stop rebuilding the ability on every login.
An ability object built from the user. When the user or plan changes, you build it again and push the rules in.
import { AbilityBuilder, createMongoAbility, subject } from '@casl/ability'
function defineAbilityFor(user: { id: string }) {
const { can, cannot, build } = new AbilityBuilder(createMongoAbility)
can('read', 'Post')
can('update', 'Post', { authorId: user.id })
cannot('delete', 'Post')
return build()
}
const ability = defineAbilityFor(user)
ability.can('update', subject('Post', post)) // true for Ada's post
// user switches account:
ability.update(defineAbilityFor(nextUser).rules)The rule reads the signal. Change the signal and every check that depends on it re-runs.
import { createPermissions } from '@pyreon/permissions'
const can = createPermissions({
'posts.read': true,
'posts.update': (post) => (post as Post | undefined)?.authorId === me().id,
'posts.delete': false,
})
can('posts.update', post) // true for Ada's post
// user switches account:
me.set(nextUser) // every check on screen re-evaluatesComing from CASL?
Action and subject become one dotted key.
// @casl/react (reads the ability from <AbilityProvider>)
<Can I="update" this={subject('Post', post)}>
<button>Edit</button>
</Can>
// in a loader or server action
ForbiddenError.from(ability).throwUnlessCan('delete', 'Post')
// throws 'Cannot execute "delete" on "Post"'The models differ: CASL matches (action, subject) pairs with MongoDB-style conditions; Pyreon checks dotted string keys, and a condition is a plain function. Conditions you wrote as { authorId: user.id } become (post) => (post as Post).authorId === me().id.
<Show when={() => can('posts.update', post)}>
<button>Edit</button>
</Show>
can.assert('posts.delete')
// throws "[Pyreon] permission denied: 'posts.delete'"Switch roles and watch the UI.
Three roles, one post written by Ada. Each button reads can(); nothing else re-renders when the role changes.
can.set({
'posts.read': true,
'posts.update': (post) => post.authorId === me().id,
'posts.delete': (post) => post.authorId === me().id,
'users.manage': false,
})- role switches (can.set)0
- can() checks on the last switch0
- post component renders0
Edit and delete are predicates: they get the post and compare its author with the signed-in user.
Post by Ada
Launch checklist
Ada (editor) can: read, edit, delete
1.3–1.9× faster than CASL when both resolve.
Both libraries must return the same boolean for every check before timing. The race uses a rule map with one ownership predicate, which switches off Pyreon's memo the way a real app does, so both sides resolve every call. Exact deny is a tie.
- resolver race (full resolution)win1.3–1.9×
- exact denytiecould not distinguish
- repeated check, static mapmeasured2.7–13.8×, a cache read, not a race
Everything can does.
can(key, context?)Reactive in JSX,computedandeffect; pass the post, the team or the order as context.can.not(key)The inverse, for "show the upgrade banner".can.all(…)/can.any(…)AND and OR over several keys, with one shared context.can.assert(key, ctx?, msg?)Throws a[Pyreon]error on deny, for loaders, guards and server actions.can.set(map)Replace every rule after login, in one batch.can.patch(map)Merge a few rules when the plan changes.can.clear()Deny everything on logout.can.granted/can.entriesComputed lists of what is granted, for a settings page or a debug panel.<PermissionsProvider>One instance per request on the server, one per test.usePermissions(['posts.edit'])A self-contained instance from a list of grants, for a story or a test, no provider needed.
Things to build with it.
The rule reads the plan signal. Upgrade, and the CSV export appears without a reload.
const plan = signal<'free' | 'pro'>('free')
const can = createPermissions({
'export.csv': () => plan() === 'pro',
'seats.invite': () => plan() !== 'free',
})
const Toolbar = () => (
<Show when={() => can('export.csv')}>
<button>Export CSV</button>
</Show>
)
plan.set('pro') // the button appearsFinance can do everything under billing except issue refunds. The more specific deny wins.
can.set({
'billing.**': true,
'billing.refunds.**': false,
'admin.*': true,
'admin.users': false,
})
can('billing.invoices.export') // true
can('billing.refunds.issue') // false
can('admin.settings') // true
can('admin.users') // false
can('admin.users.edit') // false: '*' is one segmentThree exports, one callable.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- createPermissions
- PermissionsProvider
- usePermissions
- not
- all
- any
- assert
- set
- patch
- clear
- granted
- entries
- Permissions
- PermissionMap
- PermissionValue
- PermissionPredicate
Good to know before you start.
Hiding a button is not authorization
Check again where the data lives: call can.assert() in the loader or server action, with rules built from the server's own session.
One instance per request on the server
Create the instance inside the request and pass it through <PermissionsProvider>, so two users never share rules during SSR.
* is one segment
admin.* matches admin.users but not admin.users.edit. Use admin.** for the whole subtree.
Strings, not Mongo queries
There is no condition language to serialize and send to a client. If your rules come from a database as CASL-style JSON, map them to keys and predicates once, at login.
What people ask first.
Is it faster than CASL?
On the fair race, where both libraries resolve every check because the rule map holds one ownership predicate, 1.3–1.9× (one run, bun). An exact deny ties. The record also lists 2.7–13.8× for repeated checks of a static map, and says plainly that those are a cache read, not a race.
Does a predicate re-run when the data it reads changes?
Yes, when it reads signals. can('posts.update', post) inside JSX tracks whatever the predicate reads, me() included, and re-checks when it changes.
How do I load rules after login?
can.set(rulesFor(user)) replaces the map in one batch, and every reactive check updates once. can.clear() on logout denies everything.
Can I use it outside components?
createPermissions is plain TypeScript: call can() in a route guard, a store action or a test without a provider.
Who can do what, in one function your UI already listens to.
bun add @pyreon/permissions