mcpField
S
spacetimedb-auth

spacetimedb-auth

github.com/danmossaSecurity2164 installsUpdated 19w ago
Repository

About spacetimedb-auth

spacetimedb-auth is a skill for implementing identity, claims, access control, and authorization policies in SpacetimeDB modules. It provides guidance on connection rejection, claim validation, reducer checks, and experimental RLS.

Key features

  1. 01Identity and JWT claim guidance
  2. 02Rejecting unauthenticated connections
  3. 03Issuer and audience validation
  4. 04Reducer authorization checks
  5. 05Experimental RLS guidance
  6. 06Authentication reference map

Use cases

  1. 01Designing authenticated SpacetimeDB modules
  2. 02Validating JWT claims before authorization
  3. 03Rejecting clients without authentication
  4. 04Applying row-level visibility rules

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/danmossa/spacetimedb-skills --skill spacetimedb-auth

After installing, type/spacetimedb-authin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
core-concepts-authentication-auth0.md
core-concepts-authentication-clerk.md
core-concepts-authentication-spacetimeauth-configuring-a-project.md
core-concepts-authentication-spacetimeauth-creating-a-project.md
core-concepts-authentication-spacetimeauth-react-integration.md
core-concepts-authentication-spacetimeauth-testing.md
core-concepts-authentication-spacetimeauth.md
core-concepts-authentication-usage.md
core-concepts-authentication.md
how-to-reject-client-connections.md
how-to-rls.md

Details

From the project README

Use this skill for identity, claims, access control, and authorization policy.

Core auth patterns

  • SpacetimeDB derives an Identity from the JWT sub and iss claims. Use identity for stable ownership; use JWT claims for provider, audience, role, and policy decisions.
  • Authenticated modules should reject unauthenticated clients in client_connected/clientConnected before they can subscribe or call reducers.
  • Always validate issuer and audience before trusting subject or custom claims. Claim names and expected values are deployment-specific.
  • Treat senderAuth/SenderAuth/sender_auth() as the source of JWT details, not the client-provided identity alone.
  • Use role or custom-claim helpers inside reducers for authorization checks; return sender-facing errors for expected denials.
  • RLS is experimental. Its rules are SQL filters, use :sender for the caller identity, return full rows from one table, and multiple rules for a table are ORed together. Module owners bypass RLS.

TypeScript connection rejection pattern:

import { SenderError } from "spacetimedb/server";

const OIDC_CLIENT_IDS = ["client_..."];

export const onConnect = spacetimedb.clientConnected((ctx) => {
  const jwt = ctx.senderAuth.jwt;
  if (jwt == null) throw new SenderError("Unauthorized: JWT is required");
  if (jwt.issuer !== "https://auth.spacetimedb.com/oidc") {
    throw new SenderError("Unauthorized: invalid issuer");
  }
  if (!jwt.audience.some((aud) => OIDC_CLIENT_IDS.includes(aud))) {
    throw new SenderError("Unauthorized: invalid audience");
  }
});

Reference map

NeedOpen
Auth overviewreferences/core-concepts-authentication.md
SpacetimeAuthreferences/core-concepts-authentication-spacetimeauth*.md
Third-party providersreferences/core-concepts-authentication-auth0.md, references/core-concepts-authentication-clerk.md
Claims in module codereferences/core-concepts-authentication-usage.md
Row-level security and connection rejectionreferences/how-to-rls.md, references/how-to-reject-client-connections.md

Guidance

  • Keep authentication identity checks separate from table visibility and row-level authorization choices.
  • Treat claim names, issuers, and audiences as deployment-specific; do not hard-code sample values unless they are already in the user's project.
  • Route HTTP token mechanics to spacetimedb-http when the task is endpoint-level.

Comments

Markdown supported