Skip to content

refactor(auth): single-source Better Auth config + split package exports (#45)#54

Merged
pranavp10 merged 2 commits into
mainfrom
auth-refactor-45-single-source-config
Jul 13, 2026
Merged

refactor(auth): single-source Better Auth config + split package exports (#45)#54
pranavp10 merged 2 commits into
mainfrom
auth-refactor-45-single-source-config

Conversation

@pranavp10

@pranavp10 pranavp10 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Collapses the two divergent betterAuth() configs into one runtime instance in @reloop/auth/server (auth service becomes a thin re-export).
  • Adds @reloop/auth/types and rewires the browser client so it derives types from the single source without value-importing server deps.
  • Moves signup-invite helpers + Redis secondary storage into the shared package; keeps client/types isolation under test and CI.

Closes #45

Test plan

  • bun run test in packages/auth (export isolation — 2 pass)
  • bun run test in apps/backend/auth (characterization tripwire — 6 pass)
  • bun run typecheck / check-types for @reloop/auth and be-auth
  • tsc --noEmit for dashboard, console, docs, links
  • CI BE Auth Docker workflow green (isolation + tripwire gate image build)

Greptile Summary

This PR centralizes the auth package around one Better Auth server runtime. The main changes are:

  • Shared server config and runtime exports under @reloop/auth/server.
  • Backend auth service files now re-export or consume the shared package implementation.
  • Signup-invite helpers and Redis storage moved into packages/auth.
  • New @reloop/auth/types export and client import rewiring.
  • Export-isolation tests and CI coverage for the shared auth package.

Confidence Score: 4/5

This is close, but the type export issue should be fixed before merging.

  • @reloop/auth/types still points TypeScript at the server runtime implementation.
  • Browser packages can still be forced to resolve server-only dependencies during type checking.

packages/auth/src/types.ts

Important Files Changed

Filename Overview
packages/auth/src/types.ts Adds the public type surface, but it still derives exported types from the server runtime implementation.
packages/auth/src/client.ts Updates the client to consume the new type export while keeping runtime imports client-side.
packages/auth/src/server/auth.ts Moves the Better Auth runtime into the shared server package entrypoint.
packages/auth/package.json Adds split package exports for server config and auth types.

Reviews (2): Last reviewed commit: "fix(auth): address PR #54 review finding..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

…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
Comment thread packages/auth/src/types.ts Outdated
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.
@pranavp10 pranavp10 merged commit ac1dd84 into main Jul 13, 2026
2 checks passed
@pranavp10 pranavp10 deleted the auth-refactor-45-single-source-config branch July 13, 2026 05:12
* 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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

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.

Auth refactor 2/10 — Single-source Better Auth config + split package exports

1 participant