Skip to content

Authentication and roles

Each instance uses one sign-in provider, recorded in instance_settings.auth_provider at setup: Clerk (hosted) or Better Auth (built in, with email and password stored in the instance database). The app refuses to start with a different provider, the panel does not offer a way to change it, and there is no migration path.

Only code under server/lib/auth/ and web/src/lib/auth/ may import @clerk/* or better-auth, and lint enforces it. Everything else goes through server/lib/auth/index.ts, the AuthProvider interface in types.ts, and the provider-neutral server/lib/accounts.ts. Feature code never asks which provider is active, and it never reads or writes a role at the provider. The web app selects its client from window.AUTH_PROVIDER, which /config.js sets.

server/lib/auth/TOUCHPOINTS.md lists every file that mentions Clerk. A test fails on an unlisted file, so update the list when you add or move Clerk-specific code.

users.role is either admin or the id of a roles row. The app never reads or writes anything a provider says about roles. A role change applies on the next request.

users.id is the app’s own id, and auth_identities links it to sign-in accounts. admin is a hard-coded superuser and never a row. Only an administrator can assign roles, and role assignment is not a permission, which prevents privilege escalation.

Self-registered users stay pending until an administrator, or a holder of users.approve, activates them. The first user, or the user that matches INITIAL_ADMIN_EMAIL, is an active administrator from the start.

Group Permissions
Club settings.manage, audit.view, themes.manage
Members users.view, users.approve, users.disable
Contests contests.create, contests.edit, contests.delete, contests.templates
Logging and spotting contacts.log, spots.create
Station operator operator.permanent, operator.supplemental, account.shared_computer
QSOs on others’ behalf contacts.create_any, contacts.edit_any, contacts.delete_any, contacts.request_change
Data tools tools.validate, tools.bulk_edit, tools.bulk_delete, tools.geocode, tools.duplicates
Import data.import

shared/roles.ts defines the permissions. ADMIN_AREA_PERMISSIONS decides which of them show the Admin link.

Logging does not depend on the radio. Tuning works like this:

  • Administrators and permanent operators always have the radio. Each of them has users.radio_lock on their own profile, on by default and visible only to them, and the server reads it fresh from the database on every tune. While it is on, they must press Unlock first.
  • A supplemental operator passes a frequency challenge instead.
  • Unlocks are per socket and per radio. A page reload resets them, and unlocking one radio leaves the others locked.
  • While a radio is offline, everyone is unrestricted.

See Radio bridge.

Accounts use email and password only, with 10 to 128 characters. Better Auth’s own sign-up endpoint is off, so accounts come only from createAccount(): open sign-up, an invite, an administrator or the wizard.

The app stores invite tokens as SHA-256 hashes. Each token works once, expires, and is audited without the token itself. Reset links work once and never reveal the password. Email verification, self-service reset and TOTP all need mail.

Sessions use an HTTP-only SameSite=Lax cookie. Every state-changing cookie request and every WebSocket upgrade must therefore carry an Origin for this site, which origin-guard.ts checks. Telemetry is off, the library’s log goes through ours with secrets scrubbed, and its tables are named ba_*.

The Clerk webhook mirrors only the profile, the banned flag and deletion. When you disable a member, the app bans them at Clerk first.

web/src/lib/auth/clerk.tsx contains two deliberate oddities. The router integration (routerPush and routerReplace) avoids full page loads. A key read that the bundler cannot fold stops the app from being tree-shaken away when the variable is unset. TOUCHPOINTS.md explains both.

server/auth-suite.test.ts runs one suite against both providers, and Clerk mocks only verifyToken. better-auth.test.ts covers behavior that exists only in built-in sign-in. auth-provider.test.ts drives the app with a made-up third provider, which proves the boundary holds.