Node Route.get() requires callback function but got a [object undefined]

后端 未结 1 1564
时光取名叫无心
时光取名叫无心 2021-01-06 21:54

I\'m utilizing Passport to create a Google OAuth2 authentication system. I\'m trying to write the route files in Coffeescript for it, except for some reason I keep getting t

相关标签:
1条回答
  • 2021-01-06 22:21

    You haven't set isLoggedIn before using it, so it is still undefined at that point.

    Move this:

    isLoggedIn = function(req, res, next) {
      if (req.isAuthenticated()) {
        return next();
      }
      return res.redirect('/');
    };
    

    before this line:

    router.get('/editor', isLoggedIn, function(req, res) {
    

    Or get rid of the isLoggedIn variable and use function isLoggedIn() {} syntax to have the function hoisted:

    function isLoggedIn(req, res, next) {
      if (req.isAuthenticated()) {
        return next();
      }
      return res.redirect('/');
    };
    
    0 讨论(0)
提交回复
热议问题