TypeError: jwt.sign is not a function
TypeError: jwt.sign is not a function
我包括快递等包括:
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
然后定义我的续集模型和尾声路线并将其放置在这里:
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 install 之后也是如此。
jsonwebtoken 仅用于 validate/decode jwts on express.js requests.
如果您需要签署请求,您需要使用 node-jsonwebtoken:
https://github.com/auth0/node-jsonwebtoken
GH 问题:
https://github.com/auth0/express-jwt/issues/48
这是一篇关于您正在尝试做的事情的精彩博文:
我包括快递等包括:
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
然后定义我的续集模型和尾声路线并将其放置在这里:
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 install 之后也是如此。
jsonwebtoken 仅用于 validate/decode jwts on express.js requests.
如果您需要签署请求,您需要使用 node-jsonwebtoken:
https://github.com/auth0/node-jsonwebtoken
GH 问题:
https://github.com/auth0/express-jwt/issues/48
这是一篇关于您正在尝试做的事情的精彩博文: