Passport-local / I do not understand the structure of the function

0

I'm trying to implement the authentication system on my platform using Passport, passport-local and passport-local-mongoose.

I was able to apply login authentication:

app.post("/login", passport.authenticate("local", {
    successRedirect: "/secret",
    failureRedirect: "/login"
}) ,function(req, res){
});

But I can not understand the authentication structure when registering a new user:

app.post("/register", function(req, res) {
    User.register(new User({username: req.body.username}), req.body.password, function(erro, user) {
        if(erro) {
            console.log(erro);
            return res.render("register");
        } 
        passport.authenticate('local')(req, res, function () {
            res.redirect("/secret");
        });        

    });
});

Because the structure that will make redirection after user authentication has this structure: passport.authenticate("local")(req, res, function(){}

I can not understand the role of these parentheses. What is their role?

    
asked by anonymous 02.10.2017 / 03:20

1 answer

0

This second parentheses functions as a callback of the passport authentication function. The Passport will do the validations and then use what is being passed in the second parentheses to give continuity

    
03.10.2017 / 15:53