auth.server file naming triggers import protection for TanStack Start #3008

Closed
opened 2026-03-13 10:34:06 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @GYHHAHA on GitHub (Mar 6, 2026).

I was following the steps from doc to setup a basic example for TanStack Start. However I got the warning

[import-protection] Import denied in client environment

  Denied by file pattern: **/*.server.*
  Importer: c:/Users/gyh/Desktop/Projects/myApp/src/routes/dashboard.tsx:6:27
  Import: "@/lib/auth.server"
  Resolved: src/lib/auth.server.ts

  Trace:
    1. src/router.tsx:2:27 (entry) (import "./routeTree.gen")
    2. src/routeTree.gen.ts:7:47 (import "./routes/dashboard")
    3. src/routes/dashboard.tsx:6:27 (import "@/lib/auth.server")

  Code:
    4 | export const Route = createFileRoute("/dashboard")({
    5 |   beforeLoad: async () => {
  > 6 |     const session = await getSession();
      |                           ^
    7 |
    8 |     if (!session) {

  c:/Users/gyh/Desktop/Projects/myApp/src/routes/dashboard.tsx:6:27

I take a look from TanStack Start's doc including Default Rules and File Organization. Now I think it's more reasonable to change auth.server.ts to auth.function.ts as the doc suggests. If this makes sense, I would like to make a PR. Thanks.

Originally created by @GYHHAHA on GitHub (Mar 6, 2026). I was following the steps from [doc](https://better-auth.com/docs/integrations/tanstack#protecting-resources) to setup a basic example for TanStack Start. However I got the warning ``` [import-protection] Import denied in client environment Denied by file pattern: **/*.server.* Importer: c:/Users/gyh/Desktop/Projects/myApp/src/routes/dashboard.tsx:6:27 Import: "@/lib/auth.server" Resolved: src/lib/auth.server.ts Trace: 1. src/router.tsx:2:27 (entry) (import "./routeTree.gen") 2. src/routeTree.gen.ts:7:47 (import "./routes/dashboard") 3. src/routes/dashboard.tsx:6:27 (import "@/lib/auth.server") Code: 4 | export const Route = createFileRoute("/dashboard")({ 5 | beforeLoad: async () => { > 6 | const session = await getSession(); | ^ 7 | 8 | if (!session) { c:/Users/gyh/Desktop/Projects/myApp/src/routes/dashboard.tsx:6:27 ``` I take a look from TanStack Start's doc including [Default Rules](https://tanstack.com/start/latest/docs/framework/react/guide/import-protection#default-rules) and [File Organization](https://tanstack.com/start/latest/docs/framework/react/guide/server-functions#file-organization). Now I think it's more reasonable to change `auth.server.ts` to `auth.function.ts` as the doc suggests. If this makes sense, I would like to make a PR. Thanks.
GiteaMirror added the tanstack-start label 2026-03-13 10:34:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#3008