小编Vai*_*eke的帖子

Node.js passport-jwt如何在cookie中发送令牌?

1)用户通过身份验证后,如何在Cookie中设置令牌,以便用户不会在每个请求中发送用户名密码?

2)向客户端发送令牌的理想方式是什么?

    apiRoutes.post('/authenticate', function (req, res) {
        User.findOne({
            email: req.body.email
        }, function (err, user) {
            if (err) throw err;

            if (!user) {
                res.send({ success: false, message: 'Authentication failed. User not found.' });
            } else {
                // Check if password matches
                user.comparePassword(req.body.password, function (err, isMatch) {
                    if (isMatch && !err) {
                        // Create token if the password matched and no error was thrown
                        var claims = {
                            sub: user._id,
                            email:user.email,
                            iss: 'https://NodeLogin.com',
                            permissions: user.role
                        };

                        var token = jwt.sign(claims, config.secret, { …
Run Code Online (Sandbox Code Playgroud)

node.js jwt passport.js

10
推荐指数
1
解决办法
6241
查看次数

标签 统计

jwt ×1

node.js ×1

passport.js ×1