TypeError: jwt.sign is not a function(TypeError:jwt.sign不是函数)
问题描述
我包括快递等,包括:
var expressJwt = require('express-jwt'); //https://npmjs.org/package/express-jwt
var secret = 'this is the secret secret secret 12356';
var jwt = require('jsonwebtoken'); //https://npmjs.org/package/node-jsonwebtoken
然后定义我的Sequelize模型和结尾路线,并将其放在此处:
app.post('/authenticate', function (req, res) {
//TODO validate req.body.username and req.body.password
//if is invalid, return 401
if (!(req.body.username === 'john.doe' && req.body.password === 'foobar')) {
res.status(401).send('Wrong user or password');
return;
}
var profile = {
first_name: 'John',
last_name: 'Doe',
email: 'john@doe.com',
id: 123
};
// We are sending the profile inside the token
var token = jwt.sign(profile, secret, { expiresInMinutes: 60*5 });
res.json({ token: token });
});
当我在表单中输入John.Doe和foobar时,控制台告诉我jwt.sign不是一个函数,即使在安装了NPM之后也是如此。
推荐答案
jsonWebToken仅用于验证/解码exts.js请求上的jwt。
如果需要对请求进行签名,则需要使用node-jsonwebToken:
https://github.com/auth0/node-jsonwebtoken
生长激素问题:
https://github.com/auth0/express-jwt/issues/48
这里有一篇很好的博文,介绍了你正在尝试做的事情:
https://matoski.com/article/jwt-express-node-mongoose/
这篇关于TypeError:jwt.sign不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TypeError:jwt.sign不是函数
基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
