首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >next-auth JWEDecryptionFailed

next-auth JWEDecryptionFailed
EN

Stack Overflow用户
提问于 2022-03-07 17:55:06
回答 3查看 2.2K关注 0票数 4

我正在使用这段代码,以便能够使用next-auth提供程序和认知作为oauth serviice:这允许电子邮件和密码auth。我正在运行next-auth@4.2.1:

代码语言:javascript
运行
复制
import CognitoProvider from "next-auth/providers/cognito";
import NextAuth from 'next-auth'
import CredentialsProvider from "next-auth/providers/credentials"
import * as cognito from '../../../lib/cognito'
import { Auth } from 'aws-amplify';

export default NextAuth({
    providers: [
        CredentialsProvider({
            credentials: {
              username: { label: "Username", type: "text", placeholder: "jsmith" },
              password: {  label: "Password", type: "password" }
            },
            async authorize(credentials, req) {
                try {
                    const user = await Auth.signIn(credentials.username, credentials.password);
                    return user
                } catch (error) {
                    console.log('error signing in', error);
                }
            }
          })
    ],
    debug: process.env.NODE_ENV === 'development' ? true : falsey

})

我经常会遇到这样的错误:

代码语言:javascript
运行
复制
https://next-auth.js.org/errors#jwt_session_error decryption operation failed {
  message: 'decryption operation failed',
  stack: 'JWEDecryptionFailed: decryption operation failed\n' +
    '    at gcmDecrypt (/home/aurel/Documents/repos/front/node_modules/jose/dist/node/cjs/runtime/decrypt.js:67:15)\n' +
    '    at decrypt (/home/aurel/Documents/repos/front/node_modules/jose/dist/node/cjs/runtime/decrypt.js:92:20)\n' +
    '    at flattenedDecrypt (/home/aurel/Documents/repos/front/node_modules/jose/dist/node/cjs/jwe/flattened/decrypt.js:119:52)\n' +
    '    at async compactDecrypt (/home/aurel/Documents/repos/front/node_modules/jose/dist/node/cjs/jwe/compact/decrypt.js:18:23)\n' +
    '    at async jwtDecrypt (/home/aurel/Documents/repos/front/node_modules/jose/dist/node/cjs/jwt/decrypt.js:8:23)\n' +
    '    at async Object.decode (/home/aurel/Documents/repos/front/node_modules/next-auth/jwt/index.js:64:7)\n' +
    '    at async Object.session (/home/aurel/Documents/repos/front/node_modules/next-auth/core/routes/session.js:41:28)\n' +
    '    at async NextAuthHandler (/home/aurel/Documents/repos/front/node_modules/next-auth/core/index.js:96:27)\n' +
    '    at async NextAuthNextHandler (/home/aurel/Documents/repos/front/node_modules/next-auth/next/index.js:21:19)\n' +
    '    at async /home/aurel/Documents/repos/front/node_modules/next-auth/next/index.js:57:32',
  name: 'JWEDecryptionFailed'
}

在文档中找到了错误,但是没有真正的帮助。

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-03-10 19:09:22

只是需要增加一个秘密才能让它起作用

代码语言:javascript
运行
复制
export default NextAuth({
    secret: process.env.AUTH_SECRET,
    providers: [
    ...
    ]
})
票数 11
EN

Stack Overflow用户

发布于 2022-11-07 02:43:18

NextAuth需要NEXTAUTH_SECRET环境变量来加密NextAuth.js JWT,并对电子邮件验证令牌进行散列。你可以把它放在.env文件中,就像

代码语言:javascript
运行
复制
NEXTAUTH_SECRET=say_lalisa_love_me_lalisa_love_me_hey

请参阅NextAuth参考

票数 1
EN

Stack Overflow用户

发布于 2022-04-17 13:40:19

秘密的a-dawg注释必须插入到.env.local文件中。

更多信息:https://nextjs.org/docs/basic-features/environment-variables

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71385330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档