Skip to content

fix(auth): forward rotated refresh-token cookie automatically in getAuth - #21

Merged
coopbri merged 3 commits into
masterfrom
fix/getauth-auto-forward-rotated-cookie
Aug 28, 2026
Merged

fix(auth): forward rotated refresh-token cookie automatically in getAuth#21
coopbri merged 3 commits into
masterfrom
fix/getauth-auto-forward-rotated-cookie

Conversation

@coopbri

@coopbri coopbri commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

What

getAuth now forwards Better Auth's rotated (chunked) account cookie by default via TanStack Start's getResponseHeaders().append, instead of requiring every app to wire the forwardSetCookie hook.

Why

When the hook was omitted, the browser kept replaying the pre-rotation refresh token. Past the issuer's theft-detection grace window, that tears down the whole token family, so every later refresh returns invalid_grant and token-derived data (organizations) comes back empty until a full cookie-clearing re-login. This is the "logged in long enough and the dashboard goes empty / No workspaces yet" bug.

It was silently present in 21 of 24 Omni apps that call createGetAuth (only blink, fractal, herald wired the hook). Making forwarding the default means the per-app fix collapses to a providers version bump, and no future app can forget it.

Design

  • forwardSetCookie is retained as an optional override (non-TanStack hosts, custom behavior). When supplied it wins, so the 3 apps that already wire it are unaffected and there is no double-forward.
  • The TanStack import is a lazy, optional runtime peer (@tanstack/react-start added to optional peerDependencies). A consumer without it that supplies no override keeps the prior no-op rather than crashing, so providers stays framework-agnostic.

Tests

  • New: forwards every rotated Set-Cookie chunk verbatim to the override.
  • New: no crash when neither an override nor a host forwarder is available (degrades to no-op).
  • Full suite green (324 tests), typecheck + build + lint + knip clean.

Rollout

After merge, repin @omnidotdev/providers to the merged SHA across the 21 affected apps (version bump only, no per-app code change needed).

getAuth now forwards Better Auth's rotated (chunked) account cookie by
default via TanStack Start's getResponseHeaders().append, instead of
requiring every app to wire the forwardSetCookie hook. When the hook was
omitted the browser kept replaying the pre-rotation refresh token; past
the issuer's theft-detection grace window that tore down the token
family, so token-derived data (organizations) came back empty until a
full re-login. That is the "logged in long enough and the dashboard goes
empty" bug, silently present in every app that forgot the hook.

forwardSetCookie is retained as an optional override (non-TanStack hosts,
custom behavior); when supplied it wins, so apps that already wire it are
unaffected and there is no double-forward. The TanStack import is a lazy,
optional runtime peer: a consumer without it that supplies no override
keeps the prior no-op rather than crashing.
The post-build patch that strips Bun's injected top-level
`import { createRequire } from "node:module"` (and makes node:* lazy) ran
only on build/index.js. The per-domain `auth` entry is imported by apps'
SSR code and can land in their client graph, so once getAuth gained a
dynamic import Bun injected `createRequire` into build/auth/index.js and it
went unpatched, breaking consumers' `vite build`
("createRequire is not exported by __vite-browser-external", hit in runa).
Apply the existing patch to every node-target bundle via a shared helper.
…undlers

getAuth's lazy `import("@tanstack/react-start/server")` is server-only, but
apps that pull providers/auth into their client graph made Vite follow the
literal specifier into TanStack's SSR internals (node:stream / async_hooks)
and fail the browser build (hit in runa after the createRequire fix). The
post-build patch now rewrites the literal to an IIFE-returned specifier with
@vite-ignore, so bundlers cannot statically follow it; it stays a runtime
import that only executes on the server.
@coopbri
coopbri merged commit 5b1f5ef into master Aug 28, 2026
4 checks passed
@coopbri
coopbri deleted the fix/getauth-auto-forward-rotated-cookie branch August 28, 2026 17:10
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant