Skip to content

fix(auth)!: always mount client session lifecycle - #412

Merged
onmax merged 2 commits into
mainfrom
fix/hydrated-session-refresh
Aug 24, 2026
Merged

fix(auth)!: always mount client session lifecycle#412
onmax merged 2 commits into
mainfrom
fix/hydrated-session-refresh

Conversation

@onmax

@onmax onmax commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

skipHydratedSsrGetSession currently avoids the duplicate client request by skipping rawClient.useSession() entirely. That also prevents Better Auth's session refresh manager from mounting, so focus, polling, online, and broadcast refresh stop working on hydrated SSR pages.

This keeps the existing opt-in and default behavior, but changes the optimized path to:

  • hydrate Better Auth's real session atom from Nuxt's SSR state
  • mount useSession() so Better Auth retains ownership of its refresh lifecycle
  • satisfy only the module-tagged bootstrap lookup from the hydrated state, without upstream network I/O
  • delegate later, competing, plugin, and manual session requests to the original fetch implementation

The bootstrap remains inside Better Fetch's normal hook and response pipeline. Its request identity survives supported plugin URL rewrites, query schema validation, and request-hook transformations. The controller is one-shot and fails closed if session fetching starts before Nuxt can arm it.

The docs now call out that the bootstrap response uses Nuxt's sanitized user and session shape, so the session token and custom top-level response fields remain unavailable until Better Auth's next native refresh.

Verification

  • corepack pnpm exec vitest run --maxWorkers=2 — 324 tests passed
  • focused session/config suite — 58 tests passed
  • corepack pnpm typecheck
  • corepack pnpm lint
  • corepack pnpm prepack
  • git diff --check

@vercel

vercel Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuxt-better-auth-docs Ready Ready Preview Aug 24, 2026 11:33am

@pkg-pr-new

pkg-pr-new Bot commented Aug 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxtjs/better-auth@412

commit: 591ae37

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
better-auth 591ae37 Commit Preview URL

Branch Preview URL
Aug 24 2026, 11:34 AM

@onmax onmax changed the title fix: preserve session refresh with hydrated SSR state fix(auth)!: always mount client session lifecycle Aug 24, 2026
@onmax
onmax merged commit 8c5d1b4 into main Aug 24, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 24, 2026
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