Auth

Adds user accounts, password and OAuth sign-in, email verification, and session management to a SpacetimeDB module. Exposes helpers to identify the caller in reducers and HTTP routes.

  • TypeScript
npm i @spacetimedb/auth

A self-contained user accounts module for SpacetimeDB TypeScript applications, handling sign-up, sign-in, session management, and identity verification. It lives inside your module as a submodule, contributing its own database tables, reducers, and HTTP route handlers while exposing helpers your own reducers use to identify the calling user.

  • Multi-user apps with private data: Any application where rows, documents, or game state belong to a specific user and must be hidden from others.
  • Social or OAuth sign-in: Products that want users to log in with Google or GitHub instead of managing passwords directly.
  • Email-gated workflows: Apps that need to verify ownership of an email address before granting access, or that allow users to recover accounts via password reset.
  • Session-aware real-time subscriptions: Clients that establish a SpacetimeDB connection and need that connection tied to an authenticated identity so reducers can enforce per-user access.
  • Admin-controlled deployments: Internal tools or early-access products where a small set of administrators manage configuration and can revoke sessions for any user.

When a user signs up or signs in through one of the HTTP routes your application exposes, the module creates a session and returns a token. The client presents that token when it connects to SpacetimeDB, and a binding step ties the live connection to the session. From that point on, any reducer your application defines can ask the module who is calling and get back a verified user identity, or reject the call if no valid session is attached.

Sessions, user profiles, OAuth identities, and configuration all live in private tables inside the module. A signing key, which you generate and supply once during setup, is used to produce and verify every token and derived identifier in the system. The module never generates the key itself. Administrators are the only principals who can change configuration, revoke other users' sessions, or adjust the administrator list, and the module prevents the last administrator from being removed.

OAuth flows work by redirecting the browser through the provider and back to a callback route. The module matches the returning request to the original browser using a short-lived cookie, then either creates a new account or links the provider identity to an existing one. Linking to an existing account is only allowed when both sides have a verified email address, preventing one user from silently taking over another's account.

Related modules

Authz

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.

Lethalchip0/wk

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/wk

Agents

Stores conversations and runs AI assistants inside your SpacetimeDB module, with tools that can read and update your application's data.

SpacetimeDB0/wk
Submodule

Edit details

One short paragraph describing the module.

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

A few short paragraphs at the conceptual level.