jaredhanson / passport

Simple, unobtrusive authentication for Node.js.
https://www.passportjs.org?utm_source=github&utm_medium=referral&utm_campaign=passport&utm_content=about
MIT License
22.93k stars 1.24k forks source link

Passport function callback doesn't work #866

Closed HideakiAtsuyo closed 2 years ago

HideakiAtsuyo commented 2 years ago

Hello so i'm trying to log-in and if the password isn't right it's supposed to tell it

passport.authenticate("local", {
        successRedirect: "/chat",
        failureRedirect: "/auth",
        failureFlash: true
      })(req, res, next)

work but

passport.authenticate('local', {
          failureRedirect: "/auth",
          failureFlash: true
        }),
        function(req, res) {
            res.redirect('/chat');
        }

Just make an infinite loading :)

It doesn't even do anything, even if i add a console.log to check it doesn't use it, also how can i get back the message in the new LocalStrategy to use it with req.flash ?

HideakiAtsuyo commented 2 years ago

By the way when i use the first function it work perfectly and redirect :)

jaredhanson commented 2 years ago

You aren't actually passing the function to passport:

passport.authenticate('local', {
          failureRedirect: "/auth",
          failureFlash: true
        }), // <-- The `)` closes the `passport.authenticate()` call, so the function below isn't passed as an argument.
        function(req, res) {
            res.redirect('/chat');
        }

To fix it, move the closing parenthesis:

passport.authenticate('local', {
          failureRedirect: "/auth",
          failureFlash: true
        }, 
        function(req, res) {
            res.redirect('/chat');
        }) // <-- close the function call here
Yan-Jean commented 2 years ago

If you have change your failure flash variable name you have to use type in parameters. flash