0

I'm watching a tutorial and I stumbled upon a strange syntax inside a callback func.

(err, user) => {
            if (err) {
                console.log(err);
                res.redirect('/register');
            }
            passport.authenticate('local')(req, res, () => {
                res.redirect('/campgrounds');
            });
        }

I couldn't describe the syntax to find a good answer on the web, what is happening here? Why are there parentheses next to the auth. function? Is it part of ECS and how is this concept called?

passport.authenticate('local')(req, res, () => {
                res.redirect('/campgrounds');
            });
mesh
  • 67
  • 9
i5x
  • 11
  • 3
  • 1
    That's no special "concept". `passport.authenticate('local')` returns a function that is then immediately called passing `req`, `res` and an anonymous function as arguments. Pseudo code: `const passport = { authenticate: function( origin ) { return function( request, response, callback ) { ... }; } };` – Andreas Aug 27 '20 at 11:03
  • Oh ok thanks! could you please refer to the docs? I couldn't find and explanation there. – i5x Aug 27 '20 at 11:06

0 Answers0