Skip to content

Commit 683399a

Browse files
authored
feat(nextjs): add helpful error for incorrect auth import (#8358)
1 parent b9d7773 commit 683399a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

.changeset/auth-import-error.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/nextjs": patch
3+
---
4+
5+
Add helpful TypeScript error for incorrect `auth` import path

packages/nextjs/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,17 @@ import type { ServerComponentsServerModuleTypes } from './components.server';
8181

8282
export const ClerkProvider = ComponentsModule.ClerkProvider as ServerComponentsServerModuleTypes['ClerkProvider'];
8383
export const Show = ComponentsModule.Show as ServerComponentsServerModuleTypes['Show'];
84+
85+
/**
86+
* `auth` is not available from this import path.
87+
*
88+
* **To fix this error:**
89+
* ```diff
90+
* - import { auth } from '@clerk/nextjs'
91+
* + import { auth } from '@clerk/nextjs/server'
92+
* ```
93+
*
94+
* The `auth` function is only available in server-side contexts:
95+
* API Routes, Server Components, Server Actions, and Middleware.
96+
*/
97+
export declare const auth: never;

0 commit comments

Comments
 (0)