I followed this tutorial <a href="https://ericswann.wordpress.com/201...ls-with-passport-and-jwt-json-web-token-auth/" rel="nofollow">https://ericswann.wordpress.com/201...ls-with-passport-and-jwt-json-web-token-auth/</a> and I got it working just fine. The only thing left missing is the logout functionallity. I read that I could just delete the token from the client side, but still I think it'd be a better approach to also remove it from the server.
This is my AuthController.js
How can I destroy a token?
This is my AuthController.js
Code:
var passport = require('passport');
//Triggers when user authenticates via passport
function _onPassportAuth(req, res, error, user, info) {
if (error) return res.serverError(error);
if (!user) return res.unauthorized(null, info && info.code, info && info.message);
return res.ok({
// TODO: replace with new type of cipher service
token: HashService.createToken(user),
user: user
});
}
module.exports = {
signup: function (req, res) {
User.create(_.omit(req.allParams(), 'id')).then(function (user) {
return {
// TODO: replace with new type of cipher service
token: HashService.createToken(user),
user: user
};
}).then(res.created).catch(res.serverError);
},
signin: function (req, res) {
passport.authenticate('local', _onPassportAuth.bind(this, req, res))(req, res);
}
};
How can I destroy a token?