页面正在重新加载,node.js和web控制台中没有响应:未能加载资源:服务器响应状态为404(未找到)

js4nwp54  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(160)

console.log(“after function”)被执行,但是console.log(“getuserbyusername被调用”)没有被执行,页面仍然在重新加载并且没有给出错误日志,这个问题在很多情况下发生在我身上,我找不到原因。

const Coach = require('./src/models/coache');

passport.use(new LocalStrategy({
  usernameField: 'email',
  passwordField: 'password'},
  (email, password, done) => {
    console.log("After Function");
    Coach.getUserByUsername(email, (err, user) => {
      console.log("getUserByUsername is called");                    
    });
  })
);

下面是coach.getuserbyusername函数:

module.exports.getUserByUsername = (email, callback) => {
  CoachesModel.findOne({
    where: {email: email}
  }, callback);
}

以下是整个程序:

passport.use(new LocalStrategy({
  usernameField: 'email',
  passwordField: 'password'},
  (email, password, done) => {
    console.log("After Function");
    Coach.getUserByUsername(email, (err, user) => {
      console.log("getUserByUsername is called");
      if (err) throw err;
      if (!user) {
        return done(null, false, { message: 'Unknown User' });
      }
      Coach.comparePassword(password, user.password, (err, isMatch) => {
        if (err) throw err;
        if (isMatch) {
          return done(null, user);
        } else {
          return done(null, false, { message: 'Invalid password' });
        }
      });
    });
  })
);

passport.serializeUser(function (user, done) {
  done(null, user.id);
});

passport.deserializeUser(function (id, done) {
  Coach.getUserById(id, function (err, user) {
    done(err, user);
  });
});

app.post('/login',
  passport.authenticate('local', { successRedirect: '/profile', failureRedirect: '/users/login', failureFlash: true}),
  function (req, res) {
    res.redirect('/profile');
  });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题