jsonwebtoken签名

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后面有一个空格

猜你喜欢

转载自blog.csdn.net/weixin_39675478/article/details/88121766