refactor(auth): single-source Better Auth config + split package exports (#45)#54
Merged
Merged
Conversation
…rts (#45) Collapse the type-inference-only betterAuth() stub and the auth-service runtime instance into one source of truth in @reloop/auth/server. Split exports so client/types stay free of database, Redis, and bus deps. - Move real betterAuth config, secondary storage, signup-invite helpers into packages/auth/src/server/ - Add @reloop/auth/types; client derives AuthInstance from types only - Thin be-auth to re-export the package runtime instance - Export-isolation tests + CI gate; #44 characterization still green
4 tasks
1. Replace OpenAPI Record<string, any> with a typed path-item map. 2. Single-source env: auth service spreads authServerConfig from @reloop/auth/server/config (lightweight, no betterAuth load). 3. types.ts type-imports server/auth only (not the server barrel); isolation test locks that in.
| * Value imports of this module must not pull server runtime deps into clients; | ||
| * use `import type` (enforced by export-isolation tests). | ||
| */ | ||
| import type { auth } from "./server/auth"; |
There was a problem hiding this comment.
Type Surface Still Resolves Server
import type keeps this out of the emitted bundle, but TypeScript still has to resolve ./server/auth to compute typeof auth. That module imports the server runtime graph at the top level, including DB, bus, Redis, and Better Auth adapter modules. A browser package that imports User or Session from @reloop/auth/types can still fail type checking or package resolution unless those server-only dependencies are also resolvable. Derive these exported types from a declaration-only contract instead of the runtime implementation module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
betterAuth()configs into one runtime instance in@reloop/auth/server(auth service becomes a thin re-export).@reloop/auth/typesand rewires the browser client so it derives types from the single source without value-importing server deps.Closes #45
Test plan
bun run testinpackages/auth(export isolation — 2 pass)bun run testinapps/backend/auth(characterization tripwire — 6 pass)bun run typecheck/check-typesfor@reloop/authandbe-authtsc --noEmitfor dashboard, console, docs, linksBE Auth Dockerworkflow green (isolation + tripwire gate image build)Greptile Summary
This PR centralizes the auth package around one Better Auth server runtime. The main changes are:
@reloop/auth/server.packages/auth.@reloop/auth/typesexport and client import rewiring.Confidence Score: 4/5
This is close, but the type export issue should be fixed before merging.
@reloop/auth/typesstill points TypeScript at the server runtime implementation.packages/auth/src/types.ts
Important Files Changed
Reviews (2): Last reviewed commit: "fix(auth): address PR #54 review finding..." | Re-trigger Greptile