NextAuth - Auth0
Answered
julian posted this in #help-forum
julianOP
Any quick fixes for this one? I've set up Auth0 with NextAuth. I can now login, register etc.
But when I try to access /api/hello, It just logs out of my website, and I get this "You must be signed in to view the protected content on this page."
But when I try to access /api/hello, It just logs out of my website, and I get this "You must be signed in to view the protected content on this page."
Answered by Blanc de Hotot
Create a new environment variable called NEXTAUTH_SECRET and add this to your [...nextauth].js as well:
As long as the secret supports HS512 verify algorithm it should clear up that error
...
session: {
strategy: "jwt",
},
jwt: {
secret: process.env.NEXTAUTH_SECRET,
},
...As long as the secret supports HS512 verify algorithm it should clear up that error
15 Replies
Blanc de Hotot
My environment is pretty different from yours but the thing that immediately catches my eye is
As far as I'm aware, the
getServerSession(req, res, authOptions)As far as I'm aware, the
getServerSession function should only take one paramter- authOptions. Maybe give it a try, I'll keep thinking about it and let you know if I see anything else that throws me offActually, just saw something else!
Change your import of getServerSession in hello.js to
Change your import of getServerSession in hello.js to
import { getServerSession } from "next-auth"@Blanc de Hotot Actually, just saw something else!
Change your import of getServerSession in hello.js to
`import { getServerSession } from "next-auth"`
julianOP
Didn't work. This code is directly from NextAuth's Example.. D:
Blanc de Hotot
Hm, I'll keep thinking on it and let you know, some of their code examples a little outdated
Do you have an AuthProvider in your layout?
julianOP
This is my _app.js
import Layout from '../components/Layout'
import 'bootstrap/dist/css/bootstrap.min.css';
import { SessionProvider } from "next-auth/react"
export default function MyApp({ Component, session, pageProps }) {
return (
<SessionProvider session={session}>
<Layout>
<Component {...pageProps} />
</Layout>
</SessionProvider>
)
}Blanc de Hotot
Add to your [...nextauth].js:
...
session: {
strategy: "jwt",
},
...When you try to log in do you see any of the nextauth cookies? There should be 3
julianOP
Yes
I'm getting this error:
[next-auth][error][JWT_SESSION_ERROR]
https://next-auth.js.org/errors#jwt_session_error decryption operation failed {
message: 'decryption operation failed',
stack: 'JWEDecryptionFailed: decryption operation failed\n' +
' at gcmDecrypt (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\jose\\dist\\node\\cjs\\runtime\\decrypt.js:67:15)\n' +
' at decrypt (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\jose\\dist\\node\\cjs\\runtime\\decrypt.js:92:20)\n' +
' at flattenedDecrypt (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\jose\\dist\\node\\cjs\\jwe\\flattened\\decrypt.js:119:52)\n' +
' at async compactDecrypt (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\jose\\dist\\node\\cjs\\jwe\\compact\\decrypt.js:18:23)\n' +
' at async jwtDecrypt (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\jose\\dist\\node\\cjs\\jwt\\decrypt.js:8:23)\n' +
' at async Object.decode (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\next-auth\\jwt\\index.js:64:7)\n' +
' at async Object.session (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\next-auth\\core\\routes\\session.js:43:28)\n' +
' at async AuthHandler (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\next-auth\\core\\index.js:165:27)\n' +
' at async getServerSession (C:\\Users\\Julia\\Documents\\GitHub\\moqmeetings\\node_modules\\next-auth\\next\\index.js:164:19)\n' +
' at async __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/hello.js:11:21)',
name: 'JWEDecryptionFailed'
}Blanc de Hotot
Create a new environment variable called NEXTAUTH_SECRET and add this to your [...nextauth].js as well:
As long as the secret supports HS512 verify algorithm it should clear up that error
...
session: {
strategy: "jwt",
},
jwt: {
secret: process.env.NEXTAUTH_SECRET,
},
...As long as the secret supports HS512 verify algorithm it should clear up that error
Answer
julianOP
It worked! Thanks a lot @Blanc de Hotot!
Blanc de Hotot
Sure! Let me know if you need anything else.
Also, you should consider marking this post as answered to help others with similar problems:
You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R
You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R