3
1) Sobald der Benutzer authentifiziert ist, Wie kann ich das Token in einem Cookie setzen, sodass der Benutzer bei jeder Anfrage kein Benutzername-Passwort sendet?Node.js pass-jwt Wie schicke ich Token in einem Cookie?
2) Was ist der ideale Weg, um Token an die Cline zu senden?
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 + '.');
});
Es funktioniert auch über mich. Gott segne dich :)) – durduliu2009
Froh, dir zu helfen :) –