Skip to content

feat: expose request session setter - #409

Merged
onmax merged 3 commits into
mainfrom
feat/request-session-setter
Aug 21, 2026
Merged

feat: expose request session setter#409
onmax merged 3 commits into
mainfrom
feat/request-session-setter

Conversation

@onmax

@onmax onmax commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Bearer-authenticated H3 requests can resolve a complete AppSession, but the module only exposed readers for its request cache. Integrations therefore had to assign event.context.requestSession directly, which also allowed an older in-flight cookie-session lookup to overwrite the supplied value.

This adds the server-only setRequestSession(event, session) helper so trusted authentication middleware can pass an AppSession | null to existing getRequestSession, getUserSession, and requireUserSession consumers.

Request-session contract

  • The explicit value becomes authoritative for the current request without creating, updating, or clearing a session cookie.
  • When a lookup is already running, later session readers join the setter while it waits. The older lookup only writes or clears state while it still owns the in-flight marker.
  • null is an authoritative negative cache value.
  • Rejected earlier lookups do not prevent trusted middleware from supplying its resolved session.
  • Context-less/narrowed H3 events continue through the existing request-session fallback.

The helper intentionally does not verify bearer tokens or interpret claims. The API reference requires callers to authenticate the value and enforce OAuth audience and scope restrictions before injection.

Closes #408

Verification

  • corepack pnpm exec vitest run test/get-request-session.test.ts test/require-user-session-typing.test.ts test/public-skill.test.ts — 24 tests passed on 19c4f83
  • Full corepack pnpm test with a temporary Corepack pnpm shim — 317 tests passed
  • corepack pnpm lint
  • corepack pnpm typecheck
  • corepack pnpm build:docs
  • git diff --check

@vercel

vercel Bot commented Aug 21, 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 21, 2026 3:03pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: a1f338f

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 21, 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 a1f338f Commit Preview URL

Branch Preview URL
Aug 21 2026, 03:05 PM

@onmax
onmax merged commit bd21c46 into main Aug 21, 2026
8 checks passed
@onmax
onmax deleted the feat/request-session-setter branch August 21, 2026 15:17
This was referenced Aug 21, 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.

Expose a supported request-session setter for bearer-authenticated H3 requests

1 participant