Skip to content

Replace auth and admin with a Better Auth extension (#841) - #854

Merged
jimhoyd merged 2 commits into
mainfrom
claude/auth-on-better-auth
Sep 28, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/auth-on-better-auth

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Part of #841, following the #843 proof. Chosen option: retire now, minimal.

What changes

  • @jimhoyd/urlcode-auth is a thin Better Auth 1.7.6 adapter (packages/auth/src/auth.ts):

    • It serves one mount (/api/auth/*, extension: auth) and forwards only an exact allowlist of Better Auth paths. Everything else under the mount returns 404.
    • auth: true on a route requires a verified Better Auth session, refuses cross-origin unsafe methods, and sets the user id as the request principal.
    • Route code reads context.capabilities.auth.identity.userId and never sees the Cookie or Authorization header.
    • Better Auth's rate limiter is always on. It is keyed by the client address URLCode admitted, written into a header the mount overwrites, so a client cannot choose its own bucket.
    • Sign-up is off by default. The secret and database live in operator configuration: data/auth.secret or BETTER_AUTH_SECRET, and data/auth.sqlite.
    • The operator CLI has two commands: urlcode-auth migrate and urlcode-auth create-user. Activation refuses until the tables exist, because a migration is an explicit operator step.
  • Deleted:

    • the old account system in packages/auth, and all of packages/admin
    • the recipes authenticated-handlers, headless-auth-profile and fixed-contract-adapter
    • docs/COMPOSING-A-SITE.md and docs/AUTH-BACKUP.md
    • roles, bearer keys, and the csrf token/origin policy keys. The auth route policy is now closed and empty.

    No compatibility layer, per the no-external-users decision. Roles and permissions are application data keyed by the user id; the proof shows a reviewer check done that way.

  • store, form-records and forms now use auth: true. The audit outbox cap is per store collection; auth no longer writes audit events.

  • The [Request]: Prove an embedded upstream auth provider in one local URLCode application #843 proof (proofs/private-requests) now runs on the first-party extension, and its own adapter package is deleted. The independent-package demo stays in test/fixtures/addons/greeting.

  • Docs, llms, skills, the starter and the generated references are rewritten or regenerated to match.

Evidence (macOS, Node 26)

  • npm run verify: passes. It includes test:proof, 12/12: owner privacy, reviewer approval with a concurrent race, cross-origin refusal, revoked-cookie replay, spoofed-header throttling, sandbox refusal, and audit --expect-routes 8 ready.
  • npm test: 1099 passed, 0 failed.
  • npm run test:addons: 5/5. Every extension installs, composes and serves, then signs in through Better Auth and writes as the signed-in user.
  • npm run test:package: passes.
  • Measured auth package: 13,593 bytes packed, 42,819 unpacked, 14 files. The budget is set to 18/56 KiB and 20 files.

Limits

  • Windows is not exercised locally; CI and dispatch cover it.
  • This is not an independent security review. Better Auth owns password hashing, sessions and its origin checks.

Follow-ups

🤖 Generated with Claude Code

…xtension (#841)

@jimhoyd/urlcode-auth is now a thin adapter over Better Auth: one mount
forwarding an exact allowlist of Better Auth paths, `auth: true` route
protection that sets the verified user id as the request principal, and the
request-bound `identity` capability. Accounts, sessions, password hashing and
rate limiting are Better Auth's; the operator CLI is `urlcode-auth migrate` and
`create-user`, and credentials stay in operator configuration.

Deleted: the home-grown account system in packages/auth, packages/admin, the
authenticated-handlers, headless-auth-profile and fixed-contract-adapter
recipes, COMPOSING-A-SITE and AUTH-BACKUP. The #843 proof now runs on the
first-party extension instead of its own adapter package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant