JavaScript/节点语法错误

JavaScript/节点语法错误,javascript,node.js,passport.js,Javascript,Node.js,Passport.js,我正在开发Node.js应用程序。每次我认为自己理解JavaScript时,就会有一个我不理解的曲线球朝我扔过来。目前,我正在尝试使用passport.js对用户进行身份验证。我有以下有效的代码: passport.authenticate('google')(req, res, function() { // TODO: Handle a user not authenticating // This is the happy path. It will always execute

我正在开发Node.js应用程序。每次我认为自己理解JavaScript时,就会有一个我不理解的曲线球朝我扔过来。目前,我正在尝试使用passport.js对用户进行身份验证。我有以下有效的代码:

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');
});
我的挑战是,我需要检测用户何时无法通过谷歌认证。如果他们成功了,我需要获得访问令牌。但是,我不知道如何执行这两个操作,因为我不理解此调用的语法。具体来说,我不明白什么是req、res、函数{…}


这行是不是说passport.authenticate返回一个函数。那么,req、res和函数{…}作为参数传递给passport.authenticate返回的函数?如果是这样的话,我仍然不知道如何获得谷歌返回的访问令牌

是的,这正是语法所表示的。有关如何使用代币的信息,请查看passport文档;我猜它是作为参数传递给回调的。您是否尝试过以下语法:passport.authenticate'google',{successRedirect:'/auth confirm',failureRedirect:'/login'};passport.authenticate不返回函数,完成后会调用该函数。我发现很多库都没有很好地记录回调参数,因此很难知道这些参数是什么。我不熟悉passport,肯定有人会很快出现,但有时当我像这样陷入困境时,我会在回调中输入一组参数,例如:functionp1、p2、p3、p4等{…},然后点击调试器,查看它们是什么are@DavePile:编写的代码,说明passport.authenticate接受单个字符串参数。然后它返回一个函数,该函数接受3个参数,其中第三个参数是回调。你错过了比赛。但是,在阅读了passport文档之后,我在任何地方都找不到这个用例文档,它对passport没有帮助。根据您提供的参数数量,authenticate的行为会有所不同。@slebetman:谢谢;我误解了