Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use authenticate with formidable.js? #236

Open
dantenovski opened this issue Nov 30, 2017 · 0 comments
Open

How do I use authenticate with formidable.js? #236

dantenovski opened this issue Nov 30, 2017 · 0 comments

Comments

@dantenovski
Copy link

dantenovski commented Nov 30, 2017

Last time I used authenticate for login in the following manner:

router.post('/login', parserUrlEncodedTrue, (request, res, next) => {
  console.log('logging in user');
  
  passport.authenticate('local', (err, user, info) => {
    var options = "";
    if(err){ 
      return next(err);
    }
    
    if(!user){
      return res.json({ 
        error: true, 
        message: "User doesn't exist" 
      });
    }
    
    request.logIn(user, function(err) {
      if (err){
        return next(err); 
      }
      
      return res.json({
        error: false,
        message: "Login Success"
      });
    });
  })(req, res, next);

Now I'm trying to use formidable.js and it works fine for registration but can't make it work with login.

let form = new formidable.IncomingForm();  
 form.parse(req, (err, fields, files) => {
    if(err){
      helpers.errors(err, res);
    } else { 
  passport.authenticate('local', (err, user, info) => {})(req, res, next);
}
});

passport.authenticate gets to req before it is parsed by formidable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant