Skip to content

refactor: split auth into one file per plugin and hook - #180

Open
axelhamil wants to merge 3 commits into
developfrom
refactor/178-split-auth
Open

axelhamil wants to merge 3 commits into
developfrom
refactor/178-split-auth

Conversation

@axelhamil

Copy link
Copy Markdown
Owner

Closes #178

  • apps/api/src/auth.ts (1670 lines) becomes apps/api/src/auth/: index.ts keeps the options, the plugin array and the auth singleton
  • One file per plugin (stripe, organization, sso, scim, clear-expired-ban, security-signals) and per hook (before, after, database), plus six shared helpers
  • auth-queries.ts and auth-session-payload.ts move to auth/queries.ts and auth/session-payload.ts, importers and mock.module paths follow
  • Pure relocation: same code, same di access, same plugin and hook order; the before hook reads the session through an injected reader instead of importing auth
  • Three guard tests (after hook, organization hooks, plugin order and before hook) written green on the unmodified code first, each with a mutation check
  • api-shape unchanged, real-database checks that load auth green, docs and skills point at the new paths
  • Port injection (AuthDeps, createAuth) stays for the follow-up PR

auth.ts had grown to 1670 lines mixing the BetterAuth options, five
plugins with their helpers, three hook families and the event bridge.
It now lives in apps/api/src/auth/: index.ts keeps the options, the
plugin array in its load-bearing order and the singleton, and each
plugin, hook and shared helper gets its own file. auth-queries.ts and
auth-session-payload.ts move into the folder as queries.ts and
session-payload.ts.

The move is pure relocation: every block keeps its text and its di
access, the plugin and hook order is unchanged, and the before hook
reads the session through an injected reader instead of importing the
singleton. Guard tests pinned the after hook, the organization hooks,
the plugin order and the before hook wiring on the unmodified code
first. Docs, skills and comments that cited the old paths follow.
@axelhamil axelhamil added the maintenance Tooling, CI, docs or refactor with no user-facing change label Nov 10, 2026
@axelhamil axelhamil self-assigned this Nov 10, 2026
Plugin files imported each other and the hooks imported plugin files
for the SSO entitlement gate, the seat cap and the SCIM user events.
Those helpers now live in auth/entitlements.ts, auth/seats.ts and
auth/scim-events.ts, so a plugin file never imports another plugin
file and a hook never imports a plugin file. The first-verification
policy acceptance joins email.ts, the redundant below-cap seat cases
fold into one, and the docs and path comments point at the new files.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Tooling, CI, docs or refactor with no user-facing change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split auth.ts into apps/api/src/auth with ports read from the container

1 participant