Express cannot authenticate

I follow the average video stacks made by Microsoft Visual Academy (mva). I was amazed at MVA module 3. When I enter the username and password, it is always redirected to the failure route.

passport.js:

passport.use('signup', new LocalStrategy({
        passReqToCallback : true // allows us to pass back the entire request to the callback
    },
    function(req, username, password, done) {

        if (users[username]){
            console.log('User already exists with username: ' + username);
            return done(null, false);
        }

        //store user in memory 
        users[username] = {
            username: username,
            password: createHash(password)
        }

        console.log(users[username].username + ' Registration successful');
        return done(null, users[username]);
    })
);

authenticate.js:

 router.get('/success', function(req, res){
    res.send({state: 'success', user: req.user ? req.user : null});
});

//sends failure login state back to angular
router.get('/failure', function(req, res){
    res.send({state: 'failure', user: null, message: "Invalid username or password"});
});

//log in
router.post('/login', passport.authenticate('login', {
    successRedirect: '/auth/success',
    failureRedirect: '/auth/failure'
}));

enter image description here

I really followed the steps indicated at https://github.com/hwz/chirp/tree/master/module-3

Any help is appreciated. Thanks in advance:)

+4
source share
2 answers

I think you should try changing the Content-Type to application/x-www-form-urlencoded.

0
source

Ok, so I have a solution for you. Do not send data to headers, but through the payload. Yes, that’s easy.

, passport.js. Github . !

if(users[username]){ console.log('User Not Found with username '+username); return done(null, false); }

:

if(!users[username]){ console.log('User Not Found with username '+username); return done(null, false); }

0

Source: https://habr.com/ru/post/1613158/


All Articles