-
Notifications
You must be signed in to change notification settings - Fork 392
Description
Preliminary Checks
- I have reviewed the documentation: https://clerk.com/docs
- I have searched for existing issues: https://github.com/clerk/javascript/issues
- I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)
- This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Reproduction / Replay Link
https://github.com/aasmal97/Clerk-Authentication-Dynamic-Server-Usage-Error
Publishable key
pk_test_bGVhZGluZy1kb2Jlcm1hbi00MC5jbGVyay5hY2NvdW50cy5kZXYk
Description
Issue:
Using auth()
or currentUser()
inside a server action, that is imported into a page.tsx
file, results in the following build error:
[Error]: Dynamic server usage: Page couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
This would cause/force the page to be client-rendered, potentially defeating the purpose of using nextjs. Though this goes away when the entire server action is defined within the page itself, this creates duplicate code when the same actions need to be re-used.
Steps to reproduce:
- Create a
page.tsx
file - Create a create a
action.ts
file, and create a server action, that callsauth()
orcurrentUser()
within it. - Import server action into
page.tsx
- Run
npm run build
- View log error in command line
Expected behavior:
- No build errors that indicate dynamic rendering
Actual behavior:
The following build error arises.
[Error]: Dynamic server usage: Page couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
Potential Patch
Have an optional cookies param, that allows cookies to be passed directly into auth(), so that we can define the context. This would allow us to call cookies
inside the server action, similar to this supabase issue.
Environment
System:
OS: Windows 11 10.0.22621
CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor
Memory: 22.67 GB / 47.95 GB
Binaries:
Node: 18.18.0 - C:\nodejs\node.EXE
npm: 8.3.0 - C:\nodejs\npm.CMD
Browsers:
Chrome: 121.0.6167.139
Edge: Chromium (121.0.2277.83)
Internet Explorer: 11.0.22621.1
npmPackages:
@clerk/nextjs: ^4.29.5 => 4.29.5
@types/node: ^20 => 20.11.16
@types/react: ^18 => 18.2.51
@types/react-dom: ^18 => 18.2.18
autoprefixer: ^10.0.1 => 10.4.17
eslint: ^8 => 8.56.0
eslint-config-next: 14.1.0 => 14.1.0
next: 14.1.0 => 14.1.0
postcss: ^8 => 8.4.33
react: ^18 => 18.2.0
react-dom: ^18 => 18.2.0
tailwindcss: ^3.3.0 => 3.4.1
typescript: ^5 => 5.3.3