managarten/services/mana-auth/src
Till JS 55cc75e7d3 fix(mana-auth): /api/v1/auth/login uses wrong cookie name in production
The custom /api/v1/auth/login route signs the user in via the
better-auth SDK (auth.api.signInEmail) and then forges a request to
/api/auth/token to mint a JWT, passing the session token as a synthetic
cookie header.

The cookie name was hardcoded as `mana.session_token=...`, but in
production better-auth issues the session cookie with the __Secure-
prefix (because secure: true is enabled). Get-session middleware on the
/api/auth/token side couldn't find the session under the unprefixed
name, so it returned 401 silently. Result: tokenResponse.ok was false,
the route fell through, and the response had no `accessToken` field at
all — only the bare { token, user, redirect } from signInEmail.

The frontend in @mana/shared-auth then picked this up as
`data.accessToken === undefined` and stored undefined as the JWT, while
the parallel /api/auth/sign-in/email call masked the visible damage by
setting the SSO cookie. So login *appeared* to work in the browser
(cookie present, session worked) but the JWT path was always broken.

Fix: pick the cookie name based on config.nodeEnv. In production use
__Secure-mana.session_token, in development use mana.session_token (no
__Secure- prefix because secure: false in dev).

Verified end-to-end on auth.mana.how:
  POST /api/v1/auth/login → response now includes accessToken (a real
  JWT, EdDSA, with sub/email/role/sid/tier/iss/aud claims), refreshToken
  (the session token), plus the original signInEmail fields.

The other /api/auth/get-session call sites in this file forward the
incoming request headers verbatim, so they preserve whatever real cookie
the browser sent and don't have this bug.
2026-04-08 16:20:18 +02:00
..
auth feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
db feat(mana-auth): phase 9 milestone 2 — vault recovery wrap + zero-knowledge 2026-04-07 22:05:49 +02:00
email feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
lib feat(services): create mana-auth (Hono + Bun) — Phase 5 auth rewrite 2026-03-28 02:43:44 +01:00
middleware feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
routes fix(mana-auth): /api/v1/auth/login uses wrong cookie name in production 2026-04-08 16:20:18 +02:00
services test(mana-auth): vault service integration tests against real postgres 2026-04-07 23:39:48 +02:00
config.ts feat(mana-auth): encryption vault — phase 2 (server-side master key custody) 2026-04-07 18:38:09 +02:00
index.ts feat(mana-auth): encryption vault — phase 2 (server-side master key custody) 2026-04-07 18:38:09 +02:00