Next.js Discord

Discord Forum

[next-auth][warn][NO_SECRET]

Answered
Rex posted this in #help-forum
Open in Discord
RexOP
Hello,
I'm using next-auth to make custom authentication with custom credentials, the authentication works fine but I got this warning on the console:
[next-auth][warn][NEXTAUTH_URL] 
https://next-auth.js.org/warnings#nextauth_url
[next-auth][warn][NO_SECRET]
https://next-auth.js.org/warnings#no_secret
[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 (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/runtime/decrypt.js:68:15)\n' +
    '    at decrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/runtime/decrypt.js:91:20)\n' +
    '    at async jwtDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/jwt/decrypt.js:10:23)\n' + 
    '    at async Object.decode (webpack-internal:///(rsc)/./node_modules/next-auth/jwt/index.js:44:25)\n' +
    '    at async Object.session (webpack-internal:///(rsc)/./node_modules/next-auth/core/routes/session.js:25:34)\n' +
    '    at async AuthHandler (webpack-internal:///(rsc)/./node_modules/next-auth/core/index.js:161:37)\n' +
    '    at async getServerSession (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:126:21)\n' +    
    '    at async page (webpack-internal:///(rsc)/./src/app/(admin)/login/page.tsx:20:21)',
  name: 'JWEDecryptionFailed'
}


In the .env file I have:
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="my-secret"
Answered by Rex
Ok this solves it
View full answer

6 Replies

@Rex Hello, I'm using next-auth to make custom authentication with custom credentials, the authentication works fine but I got this warning on the console: [next-auth][warn][NEXTAUTH_URL] https://next-auth.js.org/warnings#nextauth_url [next-auth][warn][NO_SECRET] https://next-auth.js.org/warnings#no_secret [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 (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/runtime/decrypt.js:68:15)\n' + ' at decrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/runtime/decrypt.js:91:20)\n' + ' at async jwtDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/cjs/jwt/decrypt.js:10:23)\n' + ' at async Object.decode (webpack-internal:///(rsc)/./node_modules/next-auth/jwt/index.js:44:25)\n' + ' at async Object.session (webpack-internal:///(rsc)/./node_modules/next-auth/core/routes/session.js:25:34)\n' + ' at async AuthHandler (webpack-internal:///(rsc)/./node_modules/next-auth/core/index.js:161:37)\n' + ' at async getServerSession (webpack-internal:///(rsc)/./node_modules/next-auth/next/index.js:126:21)\n' + ' at async page (webpack-internal:///(rsc)/./src/app/(admin)/login/page.tsx:20:21)', name: 'JWEDecryptionFailed' } In the .env file I have: sh NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="my-secret"
try add this to NextAuth
export default NextAuth({
    secret: process.env.NEXTAUTH_SECRET,
    providers: [
    ...
    ]
})
RexOP
I already have it.
export const authOptions: AuthOptions = {
    session: {
        strategy: strategy,
    },
    providers: [
        CredentialsProvider({
            name: 'Credintials',
            credentials: {
                username: {},
                password: {},
            },
            authorize: async (credentials, req) => {
               // auth logic
            },
        },
        )
    ],
    secret: process.env.NEXTAUTH_SECRET,
    pages: {
        signIn: '/login',
    }
}

export const handler = NextAuth(authOptions)

export { handler as GET, handler as POST }
try delete your cookies
on the browser
RexOP
Ok this solves it
Answer
RexOP
Thanks ❤️