JWT_SESSION_ERROR in next auth with next.js #6030
-
Question 💬In local development sign in is working fine but the Below error is thrown by next-auth while returning from our custom OAuth provider with production build at dev URL like https://dev-app.xyz.com/ NEXTAUTH_SECRET and NEXTAUTH_URL env variable is also set as per this https://next-auth.js.org/deployment ` authError { code: 'JWT_SESSION_ERROR', metadata: { code: 'ERR_JWE_DECRYPTION_FAILED', name: 'JWEDecryptionFailed', message: 'decryption operation failed', } }` How to reproduce ☕️package.json
[...nextauth].ts
Contributing 🙌🏽Yes, I am willing to help answer this question in a PR |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 12 replies
-
Downgrade to 4.18.0, the version 4.18.4 has issues and can't set the tokens somehow. |
Beta Was this translation helpful? Give feedback.
-
@Altroo Thanks for the quick reply. Downgraded to 4.18.0 but not working |
Beta Was this translation helpful? Give feedback.
-
This might be due to restrictions at the web server level in the hosting environment. Assuming you are using NodeJS and NextJS and running a web proxy behind Nginx or Apache. In OAuth 3-legged process OAuth identity server sends data back. In case when the Check web server logs and tweak the config for Suggesting based on the mention that it works locally but shows an error in deployed version |
Beta Was this translation helpful? Give feedback.
-
If you face any of the following errors, Follow these steps and the error will be fixed as My one was fixed.
Step 1 Generate a secret: To do this, open a terminal under Linux (In Window Open Hyper or CMD) and type : 2- Place this secret in an environment variable: I recommend you to put this secret in an environment variable. You can use the .env file (or .env.local) or directly your next.config.js file. Here I take the example of the next.config.js file that I prefer to work with. In this file, add the line with the value NEXTAUTH_SECRET and your secret. 3- Adding the secret in the next-auth configuration: Once your secret is set as an environment variable, next-auth must be able to access it. Under NextJS, environment variables are accessible on the server side through the process.env object and it is the NEXTAUTH_SECRET property that we are interested in here,
4- Relaunch a build: Finally, remember to run a new npm run build and you’re all set 🥳 ! |
Beta Was this translation helpful? Give feedback.
-
I got the same issue JWT session error then I noticed that the
Now it works properly, it took my 5 hours debugging to notice that! I tried many ways; update the secret, re-write the auth actions etc but it was that much easy. For role based controls. |
Beta Was this translation helpful? Give feedback.
This might be due to restrictions at the web server level in the hosting environment. Assuming you are using NodeJS and NextJS and running a web proxy behind Nginx or Apache.
In OAuth 3-legged process OAuth identity server sends data back. In case when the
Authorize
response callback URL - body or headers is too large or big, then what your hosting environment supports may give errors.Check web server logs and tweak the config for
proxy-body-size,
proxy-buffer-size
,fastcgi-buffer-size
etc, in the case of Nginx and see if it helps.Suggesting based on the mention that it works locally but shows an error in deployed version