I'm working on a Node.js app. Everytime I think I understand JavaScript, a curve ball is thrown at me that I don't understand. Currently, I'm trying to use passport.js to authenticate a user. I have the following code (which works):
passport.authenticate('google')(req, res, function() {
// TODO: Handle a user not authenticating
// This is the happy path. It will always execute. However, it should only execute if a user authenticated with google.
logger.info('user authenticated');
res.redirect(307, '/auth-confirm');
});
My challenge is, I need to detect when a user fails to authenticate with Google. If they succeed, I need to get the access token. However, I do not know how to do either of these because I do not understand the syntax of this call. Specifically, I don't understand what (req, res, function() {...}) is.
Is that line saying that passport.authenticate returns a function. So, req, res, and function() { ... } are passed as parameters to the function that passport.authenticate returns? If that's the case, I still don't know how to get the access token returned by google.