apiRoutes.post('/authenticate', function(req, res) {
User.findOne({
name: req.body.name
}, function(err, user) {
if (err) throw err;
if (!user) {
res.send({success: false, msg: 'Authentication failed. User not found.'});
} else {
// check if password matches
user.comparePassword(req.body.password, function (err, isMatch) {
if (isMatch && !err) {
// if user is found and password is right create a token
var expires=moment().add(1,'days').valueOf();
var token = jwt.encode(user, config.secret,{
exp: expires});
// return the information including token as JSON
res.json({success: true, token: 'JWT ' + token});
} else {
res.send({success: false, msg: 'Authentication failed. Wrong password.'});
}
});
}
});
});
它提示錯誤: /home/oracle/node/ang_backend1/node_modules/jwt-simple/lib/jwt.js:130 拋出新的錯誤('算法不支持'); ^如何添加到期日期智威湯遜 - 簡單令牌
錯誤:在/家裏Object.jwt_encode [如編碼(/home/oracle/node/ang_backend1/node_modules/jwt-simple/lib/jwt.js:130:11) 不支持 算法/oracle/node/ang_backend1/app.js:198:27 at /home/oracle/node/ang_backend1/app/models/user.js:48:9 at/home/oracle/node/ang_backend1/node_modules/bcryptjs /dist/bcrypt.js:261:17 at /home/oracle/node/ang_backend1/node_modules/bcryptjs/dist/bcrypt.js:1198:21 at Immediate.next [as_onImmediate](/ home/oracle/node /ang_backend1/node_modules/bcryptjs/dist/bcrypt.js:1078:21) 在processImmediate [按_immediateCallback](timers.js:383:17)
它仍然提示同樣的錯誤添加app.get後('jwtTokenSecret'),還有其他建議嗎? –
任何人都可以幫忙?謝謝 –