Skip to content

feat(vps): port better-auth route onto the Effect router (Step 2c)#146

Open
guidefari wants to merge 1 commit into
migration/2b-swap-entry-pointfrom
migration/2c-better-auth-route
Open

feat(vps): port better-auth route onto the Effect router (Step 2c)#146
guidefari wants to merge 1 commit into
migration/2b-swap-entry-pointfrom
migration/2c-better-auth-route

Conversation

@guidefari

Copy link
Copy Markdown
Owner

Why this exists: /auth/* has to work correctly on the new router before any authed route can be trusted on it. This isolates that one third-party routing integration into its own diff, separate from the topology cutover in #145 -- if auth breaks, it's this PR, not a tangle of unrelated changes.

Stacked on #145 (merge #142 -> #143 -> #144 -> #145 first).

Verification

  • New tests hit /auth/get-session and /auth/does-not-exist through the live handler and confirm better-auth's own responses come back, not the Hono fallback's 404 -- proves route precedence empirically rather than trusting the doc's claim about it.
  • Full suite: 142/142 passing (140 existing + 2 new), 15 files.
  • Confirmed betterAuthMiddleware/attachSessionContext (used by other authed routes) are unaffected -- they call auth.api.getSession() directly, independent of the /auth HTTP route.

Next

Step 3a: port health handlers to HttpApiBuilder.group, taking /health* over from the fallback -- first real HttpApi group serving real traffic.

Step 2c of the Hono -> Effect HttpApi migration
(docs/migration-effect-http-api.md). Isolates the one third-party
routing integration so an auth regression is diagnosable to this
one small diff, separate from the topology cutover in 2b.

Why this exists: /auth/* now needs to be handled correctly before
any authed route can be trusted on the new router. better-auth owns
its own routing (auth.handler is opaque), so it can't become an
HttpApiEndpoint -- it's mounted as its own wildcard route ahead of
the Hono fallback, same basePath as before.

- apps/vps/src/http/routes.ts: new betterAuthRoute wildcards
  /auth/* to auth.handler(prepareAuthRequest(...)), registered
  before honoFallback in the layer so it takes precedence.
- apps/vps/src/routes/user/better-auth.routes.ts: exported
  prepareAuthRequest so it's reusable outside the Hono wrapper.
- apps/vps/src/app.ts: removed the Hono /auth mount -- it's not
  used anywhere else (no other test or code path calls app.fetch
  directly since Step 2b made effectWebHandler the sole entry
  point). betterAuthMiddleware/attachSessionContext are unaffected;
  they call auth.api.getSession() directly, independent of the
  /auth HTTP route.

Verified router precedence empirically rather than trusting the doc's
claim: new tests hit /auth/get-session and /auth/does-not-exist
through the live handler and confirm better-auth's own responses are
returned, not the Hono fallback's 404. Full apps/vps suite:
142/142 passing (140 existing + 2 new), across 15 files.
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