Skip to content

Instantly share code, notes, and snippets.

@passatgt
Created August 9, 2016 15:20
Show Gist options
  • Save passatgt/d1094ce2354a51958a8b941af46a72c2 to your computer and use it in GitHub Desktop.
Save passatgt/d1094ce2354a51958a8b941af46a72c2 to your computer and use it in GitHub Desktop.
Delete all access and refresh tokens for logged in user in Stormpath Express
//Sign out -> delete all access and refresh tokens
module.exports.signOut = function(req, res){
//Delete refresh tokens
req.user.getRefreshTokens(function(err,refreshTokens){
refreshTokens.each(deleteToken, function (err) {
if(err) {
res.status(400).send({ message: 'Oops! There was an error: ' + err.userMessage});
} else {
//And access tokens too
req.user.getAccessTokens(function(err,accessTokens){
accessTokens.each(deleteToken, function (err) {
if(err) {
res.status(400).send({ message: 'Oops! There was an error: ' + err.userMessage});
} else {
res.status(200).send({code: 'success', message: 'You are now signed out from everywhere!'});
}
});
});
}
});
function deleteToken(token, callback) {
token.delete(function(err) {
callback();
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment