Q:

passport local strategy's not getting called

I'm currently making app with vue & express.
I adopted passport as authentication library and I've used it several times.
so I know that when I make login request, passport middleware authenticates user by 'xx strategy'.
The problem is register request works well but login isn't.
I constantly get 'false' for response.data.
I can't even guess where the false comes from.
There is no return statements that returns false.
follow is my code.
passport.deserializeUser((authId, done) => {
  let hasUser
  let users = User.findOneByAuthId(authId)
  .then(results => (hasUser = results.length))

  if (hasUser) {
    console.log('deserialize!')
    done(null, users[0])
  } else {
    console.log('no user')
    done(null, { message: 'no user' })
  }
})

passport.use(new LocalStrategy(
  (username, password, done) => {
    let hasUser
    let users = User.findOneByEmail(username)
    .then(results => (hasUser = results.length))

    if (hasUser) {
      let user = users[0]
      let { hash } = user

      if (User.checkPassword(password, hash)) {
        done(null, { message: 'success' })
      } else {
        done(null, { message: 'wrong password' })
      }
    } else {
      done(null, { message: 'wrong email' })
    }
  }
))

router.post('/register', (req, res) => {
  if (!fun.emailChecker(req.body.username)) {
    return res.status(403).json({
      message: 'Invalid Email'
    })
  }

  if (!fun.passwordChecker(req.body.password)) {
    return res.status(403).json({
      message: 'Invalid Password'
    })
  }

  let hasUser
  User.findOneByEmail(req.body.username)
  .then(results => (hasUser = results.length))

  if (hasUser) {
    return res.status(409).json({
      message: 'Email Exist'
    })
  } else {
    let user = {
      authId: 'local: ' + req.body.username,
      email: req.body.username,
      hash: User.hashPassword(req.body.password),
      displayName: req.body.displayName
    }

    User.create(user)
    .then(results => {
      if (!results) {
        throw new Error('user creation error')
      } else {
        req.login(user, err => {
          if (!err) {
            req.session.save(() => {
              return res.json({ success: true })
            })
          }
        })
      }
    })
  }
})

router.post('/login', (req, res) => {
  passport.authenticate('local', (err, result) => {
    if (!err) {
      return res.json(result)
    }
  })(req, res)
})

// vue component
methods: {
onSubmit () {
  axios.post('http://localhost:3001/auth/login', {
    email: this.email,
    password: this.password
  }).then(response => console.log(response.data))
},

A:

There are various issues with your code.
Starting with incorrect promise handling:
let hasUser
let users = User.findOneByAuthId(authId)
.then(results => (hasUser = results.length))

if (hasUser) { ... }

You are trying to make asynchronous code synchronous here. The code that depends on the result of the asynchronous query has to be moved to inside the then handler (both in deserializeUser and the strategy verification handler):
User.findOneByAuthId(authId).then(users => {
  let hasUser = users.length;

  if (hasUser) {
    console.log('deserialize!')
    done(null, users[0]);
  } else {
    console.log('no user')
    done(Error('no user'));
  }
});

(I'm not quite sure why your method findOneByAuthId, whose name implies that there will be at most one result, could result in an array)
Also, you're not using the correct convention for passing user data and login errors back to Passport:
if (User.checkPassword(password, hash)) {
  done(null, { message: 'success' })
} else {
  done(null, { message: 'wrong password' })
}

This should look like this (and obviously, other places where done is called incorrectly should be fixed too):
if (User.checkPassword(password, hash)) {
  done(null, user);
} else {
  done(null, false, { message: 'wrong password' })
}

(documented here under "Verify Callback")
Finally, you're using passport.authenticate() incorrectly, which is probably the cause of the false being returned. Instead, try this:
router.post('/login', passport.authenticate('local'), (req, res) => {
  return res.json(req.user); // or whatever you want to return in case of login success
})

(documented here; if you want to use a custom callback, look for "Custom Callback" on that page)

