Passport local returns error 400 bad request with Angular

前端 未结 4 2222
庸人自扰
庸人自扰 2021-02-12 12:18

I am trying to integrate passport to my code\'s login form. Client side calling server side works as it should until i call passport.authenticate in the request, 400 Bad Request

4条回答
  •  借酒劲吻你
    2021-02-12 12:46

    This error also comes from trying to access the HTML DOM elements without using body-parser

    body-parser is a module that let's you traverse the html document tree to read response especially in case of input fields

    Use -

    var parser = require('body-parser');
    var urlencodedParser = parser.urlencoded({extended : false});
    
    
        app.post("/authenticate", urlencodedParser, passport.authenticate('local'), function (request, response)
        {           
            response.redirect('/');                      
        });
    

提交回复
热议问题