Authz

Community

Roles, scopes and grants for multi-user modules: wildcard permissions, role inheritance, scope trees, expiring grants, invite links, an audit log and row-level security, with no privilege escalation.

    npm i @pogly/spacetimedb-authz

    The authorization layer most multi-user SpacetimeDB modules end up writing by hand. You define roles as sets of permissions, with wildcards (doc.*) and inheritance, and grant them to identities on a scope. Scopes form a tree (organisation → project → document), and a grant flows down to everything below it. Grants can expire, invite links hand out a role, and every change lands in an audit log.

    Nobody can grant more than they hold, so there's no privilege escalation, even through invites or role edits.

    • Use it any time more than one person shares data and they shouldn't all see or change everything: team workspaces, shared documents, game guilds and clans, moderation tools, admin panels.
    • It replaces the usual is_admin booleans and per-table owner checks with one model you can query and audit.

    Mount it with schema({ ..., authz }), then call authz.require(ctx.as.authz, 'doc.write', doc.scopeId) at the top of any reducer. It throws, rolling back the transaction, when the caller lacks the permission.

    Reads are protected too. The module materialises what each client may see, so you add row-level-security rules with authz.rlsFor('doc', 'scope_id', 'doc.read', 'authz'), and clients only receive rows they're allowed to read.

    Bootstrap the first admin and your roles in init. Rust and C# drop-in versions share the same schema, so one client works with all three.

    Related submodules

    OAuth

    Link Twitch, Discord, Google, GitHub or Spotify accounts to SpacetimeDB identities: authorization code + PKCE, a private token vault, and scheduled refresh, with no auth server on the side.

    Lethalchip0/wkCommunity

    Cron

    Schedules recurring tasks in a SpacetimeDB module using calendar expressions or fixed intervals. Supports time zones, per-job arguments, failure limits, and runtime schedule changes.

    SpacetimeDB0/wk

    Crypto

    Hashing, encoding conversion, and webhook signature verification for Stripe, Svix, and GitHub. Includes timing-safe byte comparison and hex/base64 helpers.

    SpacetimeDB0/wk
    Submodule

    Edit details

    One short paragraph describing the submodule.

    A few bullets for scenarios where this is a good fit.

    A few short paragraphs at the conceptual level.