3
1) 사용자가 인증되면 쿠키에서 토큰을 설정하여 사용자가 각 요청에서 사용자 이름 암호를 보내지 않도록하려면 어떻게해야합니까?Node.js passport-jwt 쿠키에 토큰을 보내는 방법은 무엇입니까?
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, {
expiresIn: 60 // in seconds
});
res.json({ success: true, token: 'JWT ' + token });
} else {
res.send({ success: false, message: 'Authentication failed. Passwords did not match.' });
}
});
}
});
});
apiRoutes.get('/dashboard',
passport.authenticate('jwt', { session: false }), function (req, res) {
res.send('Worked' + req.user._id + '.');
});
그것은 나에도 작동합니다. 신의 축복 :)) – durduliu2009
당신을 도울 수있어서 다행 :) –