gpt4 book ai didi

javascript - if (!options.algorithms) throw new Error ('algorithms should be set' );错误 : algorithms should be set

转载 作者:行者123 更新时间:2023-12-03 06:49:35 31 4
gpt4 key购买 nike

我开始学习 Nodejs,但我被困在中间的某个地方。我从 npm 安装了一个新库,它是 express -jwt ,它在运行后显示某种错误。附上代码和错误日志,请帮助我!

const jwt = require('jsonwebtoken');
require('dotenv').config()
const expressJwt = require('express-jwt');
const User = require('../models/user');




exports.requireSignin = expressJwt({ secret: process.env.JWT_SECRET});
下面是错误的日志。
[nodemon] starting `node app.js`
D:\shubh\proj\Nodejs\nodeapi\node_modules\express-jwt\lib\index.js:22
if (!options.algorithms) throw new Error('algorithms should be set');
^

**Error: algorithms should be set**
at module.exports (D:\shubh\proj\Nodejs\nodeapi\node_modules\express-jwt\lib\index.js:22:34)
at Object.<anonymous> (D:\shubh\proj\Nodejs\nodeapi\controllers\auth.js:64:26)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)

最佳答案

您应该将算法属性添加到 jwt 构造函数。
例子;

expressJwt({ secret:  process.env.JWT_SECRET, algorithms: ['RS256'] });

关于javascript - if (!options.algorithms) throw new Error ('algorithms should be set' );错误 : algorithms should be set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62665636/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com