[TanStack Start documentation] auth.server.ts naming conflicts with Vite import protection #3027

Closed
opened 2026-03-13 10:35:10 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @PierreBerger on GitHub (Mar 10, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Issue

The TanStack Start integration guide recommends creating server helpers in
auth.server.ts and importing them directly in route files:

  // src/routes/dashboard.tsx
  import { getSession } from '@/lib/auth.server'

  export const Route = createFileRoute('/dashboard')({
    beforeLoad: async () => {
      const session = await getSession()
      ...
    },
  })

However, TanStack Start has a Vite plugin that blocks any file matching
**/.server. from being imported in client-side code:

[import-protection] Import denied in client environment

 Denied by file pattern: **/*.server.*
 Importer: src/routes/dashboard.tsx
 Import: "src/lib/auth.server"
 Resolved: src/lib/auth.server.ts

To Reproduce

  1. Follow the TanStack Start integration guide
  2. Create src/lib/auth.server.ts with getSession / ensureSession
  3. Import getSession in a route's beforeLoad
  4. build application, and see error

Suggestion

Update the doc example to use a filename that doesn't conflict with TanStack
Start's import protection, e.g. src/lib/auth.function.ts.

Current vs. Expected behavior

Image

What version of Better Auth are you using?

1.5.3

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000",
    "release": "24.1.0",
    "cpuCount": 8,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.67 GB"
  },
  "node": {
    "version": "v24.12.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.5.3",
    "config": {
      "emailAndPassword": {
        "enabled": true
      },
      "plugins": [
        {
          "name": "tanstack-start-cookies",
          "config": {
            "id": "tanstack-start-cookies",
            "hooks": {
              "after": [
                {}
              ]
            }
          }
        }
      ]
    }
  }
}

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 @PierreBerger on GitHub (Mar 10, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ## Issue The TanStack Start integration guide recommends creating server helpers in `auth.server.ts` and importing them directly in route files: ```ts // src/routes/dashboard.tsx import { getSession } from '@/lib/auth.server' export const Route = createFileRoute('/dashboard')({ beforeLoad: async () => { const session = await getSession() ... }, }) ``` However, TanStack Start has a Vite plugin that blocks any file matching **/*.server.* from being imported in client-side code: ```[tanstack-start-core:import-protection] [plugin tanstack-start-core:import-protection] [import-protection] Import denied in client environment Denied by file pattern: **/*.server.* Importer: src/routes/dashboard.tsx Import: "src/lib/auth.server" Resolved: src/lib/auth.server.ts ``` ### To Reproduce 1. Follow the [TanStack Start integration guide](https://better-auth.com/docs/integrations/tanstack) 2. Create src/lib/auth.server.ts with getSession / ensureSession 3. Import getSession in a route's beforeLoad 4. build application, and see error ### Suggestion Update the doc example to use a filename that doesn't conflict with TanStack Start's import protection, e.g. src/lib/auth.function.ts. ### Current vs. Expected behavior <img width="943" height="567" alt="Image" src="https://github.com/user-attachments/assets/6ffc1d00-e2db-4e5a-ac3c-4e30b62ab1c2" /> ### What version of Better Auth are you using? 1.5.3 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000", "release": "24.1.0", "cpuCount": 8, "cpuModel": "Apple M1 Pro", "totalMemory": "32.00 GB", "freeMemory": "0.67 GB" }, "node": { "version": "v24.12.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "react", "version": "^19.2.0" } ], "databases": null, "betterAuth": { "version": "^1.5.3", "config": { "emailAndPassword": { "enabled": true }, "plugins": [ { "name": "tanstack-start-cookies", "config": { "id": "tanstack-start-cookies", "hooks": { "after": [ {} ] } } } ] } } } ``` ### 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 documentation label 2026-03-13 10:35:10 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 10, 2026):

Hi @PierreBerger! I'm Dosu and I’m helping the better-auth team.

This is a duplicate of #8451, which documents the same conflict between auth.server.ts naming and TanStack Start's import protection.

Your suggested fix (renaming to auth.function.ts) is correct and aligns with the workaround identified in that issue. The documentation should be updated to use a naming pattern that doesn't trigger TanStack Start's **/*.server.* import protection.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Mar 10, 2026): <!-- Greeting --> Hi @PierreBerger! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a duplicate of [#8451](https://github.com/better-auth/better-auth/issues/8451), which documents the same conflict between `auth.server.ts` naming and TanStack Start's import protection. Your suggested fix (renaming to `auth.function.ts`) is correct and aligns with the workaround identified in that issue. The documentation should be updated to use a naming pattern that doesn't trigger TanStack Start's `**/*.server.*` import protection. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/8308b5e0-0268-48d6-8945-724757c0338f?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20duplicate%20of%20%5B%238451%5D%28https%3A//github.com/better-auth/better-auth/issues/8451%29%2C%20which%20documents%20the%20same%20conflict%20between%20%60auth.server.ts%60%20naming%20and%20TanStack%20Start%27s%20import%20protection.%0A%0AYour%20suggested%20fix%20%28renaming%20to%20%60auth.function.ts%60%29%20is%20correct%20and%20aligns%20with%20the%20workaround%20identified%20in%20that%20issue.%20The%20documentation%20should%20be%20updated%20to%20use%20a%20naming%20pattern%20that%20doesn%27t%20trigger%20TanStack%20Start%27s%20%60%2A%2A/%2A.server.%2A%60%20import%20protection.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8540)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#3027