Skip to content
@pyreon/permissions
fundamentals · access control

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
Documentation
one call
can('posts.update', post)Rules are true, false or 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, any lower to a native runtimeNative targets are experimental.
Downgrade the plan and the Export button hides itself Schematic: a plan signal switches from pro to free. The rule 'reports.export': () => plan() === 'pro' re-checks, can('reports.export') turns false, and the Export button in the toolbar disappears while Edit and Share stay as they are. Then the plan goes back to pro and Export returns. CREATEPERMISSIONS · ONE REACTIVE CAN() plan() 'pro' 'free' rule 'reports.export': () => plan() === 'pro' can('reports.export') → true → false Edit Share Export Edit and Share never read plan(), so they stay as they are roles · ownership · flags · plan tiers · wildcards like 'posts.*'
  • 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 →
why teams pick it

Access rules that keep up with the user.

  1. Rules that read signals re-check by themselves

    'posts.update': (post) => (post as Post).authorId === me().id. Switch accounts with me.set(…) and every can('posts.update', post) on screen re-evaluates. Nothing to rebuild, no ability.update(rules).

  2. 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.

  3. Wildcards with a clear winner

    billing.** grants the subtree, billing.refunds.**: false carves out refunds. Lookups go exact, then *, then **, most specific first, so the deny wins.

  4. 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.

the difference

Stop rebuilding the ability on every login.

CASL 7

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)
with @pyreon/permissions

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-evaluates
coming from

Coming from CASL?

Action and subject become one dotted key.

CASL
// @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"'
Pyreon

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'"
try it

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.

signed in as Ada · editor
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

benchmarks

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.

vs @casl/ability 7 · bun/JavaScriptCore, one process per operation and libraryPyreonrival · lower is better
  • resolver race (full resolution)
    win1.3–1.9×
  • exact deny
    tiecould not distinguish
  • repeated check, static map
    measured2.7–13.8×, a cache read, not a race
Apple M3 Max · record of 2026-11-05 · overnight run, one run · author-run, syntheticFull method, every loss →
what's included

Everything can does.

  • can(key, context?) Reactive in JSX, computed and effect; 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.entries Computed 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.
recipes

Things to build with it.

Plan tiers as rules

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 appears
Grant a subtree, carve out one branch

Finance 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 segment
api

Three exports, one callable.

Every export has a reference page with its signature, an example and the mistakes people make with it.

create · 3
  • createPermissions
  • PermissionsProvider
  • usePermissions
check (methods on the instance) · 4
  • not
  • all
  • any
  • assert
update (methods on the instance) · 3
  • set
  • patch
  • clear
inspect (computed on the instance) · 2
  • granted
  • entries
types · 4
  • Permissions
  • PermissionMap
  • PermissionValue
  • PermissionPredicate
good to know

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.

questions

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
Read the permissions guide