我一直关注微软视觉学院(mva)完成的平均堆栈视频.我对MVA模块3感到震惊.当我输入用户名和密码时,它总是重定向到失败路由. passport.js: passport.use('signup', new LocalStrategy({ passReqToCallback
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' }));
我实际上遵循了https://github.com/hwz/chirp/tree/master/module-3中给出的步骤
任何帮助表示赞赏.提前致谢 :)
我认为您应该尝试将Content-Type更改为application / x-www-form-urlencoded.