JWT JS中的几个角色

时间:2019-05-29 18:53:27

标签: javascript node.js jwt

我想创建一个函数来从包含用户名和同一用户权限的单个数组中对其进行解码的函数?

var app = express();
var apiRoutes = express.Router();
apiRoutes.use(function (req, res, next) {

    var token = req.body.token || req.param('token') || req.headers['x-access-token'];

    if (token) {
        jwt.verify(token, app.get('superSecret'), function (err, decoded) {
            if (err) {
                return res.json({ success: false, message: 'Failed to authenticate token.' });
            } else {
                req.decoded = decoded;
                next();
            }
        });

    } else {
        return res.status(403).send({
            success: false,
            message: 'No token provided.'
        });
    }
});

apiRoutes.get('/check', function (req, res) {
    //...
}); // enter code here

app.use('/api', apiRoutes);

0 个答案:

没有答案