Skip to content
Docs
Changelog

Authentication has one composition root

The 830-line packages/auth entry is split into options, hooks, effects and handler. The package root only composes them, and a request scope takes an explicit factory instead of one bound when a module is imported.

Markdown

  • One job per module. packages/auth/src/index.ts was the Better Auth configuration, its hooks, the transactional handler and the request scope factory in one file. It is now auth-options.ts, auth-hooks.ts, auth-effects.ts (the Audit Events, emails and storage deletes a write causes, registered on its unit of work) and auth-handler.ts (createAuth). Behavior is unchanged. See backend conventions and the auth package. (#268)
  • The root composes and exports one function. @fofo/auth exports createRequestScope, built from createDb and createAuth, and nothing else. No module of the package imports it.
  • An explicit factory. createRequestScopes(open) in @fofo/auth/request-scope returns the memoized createRequestScope of one composition root. bindRequestScopeCreate is gone: importing the root no longer installs a factory into another module, createRequestScope can no longer throw "request scope factory is not bound", and a test builds its own scopes instead of binding a stub that later tests share.
  • The file-size baseline shrinks. The largest backend file left the list of files over 400 lines; seven remain.
  • For template users. Import createAuth and AuthInstance from @fofo/auth/auth-handler (a new export, server-only). A test that called bindRequestScopeCreate(stub) writes const createRequestScope = createRequestScopes(stub). scripts/remove-mcp.mjs and scripts/remove-server-billing.mjs edit auth-options.ts and auth-hooks.ts.
Edit on GitHubDocumentation is in English.
Cookie settings
We use essential cookies to make our app work. With your consent, we also use optional cookies to improve your experience.

Read our Cookie Policy and Privacy Policy.