jsonwebtoken签名
#安装jsonwebtoken
npm install jsonwebtoken
#jwt签名
const jwt = require('jsonwebtoken');
const rule = {
id: user.id,
email: user.email,
password: user.password
}
jwt.sign(rule, 'secret', { expiresIn: 60 * 60 }, (err, token) => {
token = 'Bearer ' + token;
});
注意,token最后需要拼接成'Bearer ' + token,特别注意Bearer后面有一个空格