[GH-ISSUE #6818] Tanstack-start: integration docs are wrong now (should use getRequestHeaders) #19273

Closed
opened 2026-04-15 18:09:05 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @rburgst on GitHub (Dec 17, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6818

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

the docs at
https://www.better-auth.com/docs/integrations/tanstack
state that the middleware gets a request object, which is no longer true

import { redirect } from "@tanstack/react-router";
import { createMiddleware } from "@tanstack/react-start";
import { auth } from "./auth";

export const authMiddleware = createMiddleware().server(
    async ({ next, request }) => {
        const session = await auth.api.getSession({ headers: request.headers })

        if (!session) {
            throw redirect({ to: "/login" })
        }

        return await next()
    }
);

Current vs. Expected behavior

instead you need to use `

import {
  getRequestHeaders,
} from '@tanstack/react-start/server'
...
        const session = await auth.api.getSession({ headers: getRequestHeaders() })

What version of Better Auth are you using?

N/A (live docs)

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000",
    "release": "25.1.0",
    "cpuCount": 8,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.33 GB"
  },
  "node": {
    "version": "v24.11.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.1"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.3"
    }
  ],
  "databases": [
    {
      "name": "drizzle",
      "version": "^0.45.1"
    },

Which area(s) are affected? (Select all that apply)

Documentation

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @rburgst on GitHub (Dec 17, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6818 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce the docs at https://www.better-auth.com/docs/integrations/tanstack state that the middleware gets a request object, which is no longer true ```typescript import { redirect } from "@tanstack/react-router"; import { createMiddleware } from "@tanstack/react-start"; import { auth } from "./auth"; export const authMiddleware = createMiddleware().server( async ({ next, request }) => { const session = await auth.api.getSession({ headers: request.headers }) if (!session) { throw redirect({ to: "/login" }) } return await next() } ); ``` ### Current vs. Expected behavior instead you need to use ` ```typescript import { getRequestHeaders, } from '@tanstack/react-start/server' ... const session = await auth.api.getSession({ headers: getRequestHeaders() }) ``` ### What version of Better Auth are you using? N/A (live docs) ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000", "release": "25.1.0", "cpuCount": 8, "cpuModel": "Apple M1 Pro", "totalMemory": "32.00 GB", "freeMemory": "0.33 GB" }, "node": { "version": "v24.11.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.1" }, "frameworks": [ { "name": "react", "version": "19.2.3" } ], "databases": [ { "name": "drizzle", "version": "^0.45.1" }, ``` ### Which area(s) are affected? (Select all that apply) Documentation ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 18:09:05 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 17, 2025):

Thanks for raising this issue! It looks like the documentation is currently still showing the old approach of getting headers directly from the request object. With the current version, you should call getRequestHeaders() from @tanstack/react-start/server to correctly retrieve the headers when checking the session. Could you confirm that updating your middleware to use getRequestHeaders() resolves the problem? Tag @better-auth-agent if you would like an answer from the Agent. What other integrations or changes have you noticed that might need updated guidance?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3663863807 --> @better-auth-agent[bot] commented on GitHub (Dec 17, 2025): Thanks for raising this issue! It looks like the documentation is currently still showing the old approach of getting headers directly from the request object. With the current version, you should call getRequestHeaders() from @tanstack/react-start/server to correctly retrieve the headers when checking the session. Could you confirm that updating your middleware to use getRequestHeaders() resolves the problem? Tag @better-auth-agent if you would like an answer from the Agent. What other integrations or changes have you noticed that might need updated guidance? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19273