Created
August 9, 2016 15:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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