J
J
jtag2019-08-20 08:33:35
JavaScript
jtag, 2019-08-20 08:33:35

Why is it necessary to use the passport local strategy to verify a user?

Why use the passport local strategy to check the user? If you can check the user without a passport?

module.exports = function(passport) {
    passport.use('local-signin',
      new LocalStrategy({
          usernameField : 'email',    
          passwordField : 'password',
      },
      async (email, password, callback)=>{ 
        if(email && password) {
          let result = await sqlQuery("SELECT * FROM users WHERE username = '"+email+"'"); // проверка юзера
          if (!result.length) {
            console.log("юзер не найден");
            return callback(null, false, {message: 'Incorrect email'});
          }

          let res = bcrypt.compareSync(password, result[0].password); 
          if(res) {
            console.log("Пароль совпал", result[0])
            return callback(null, result[0])
          }else {
            return callback(null, false, {message: 'Incorrect email or password'});
          }
        }
      })
    );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-08-20
@Xuxicheta

interface standardization. The presence of uniform checks in passport made it possible to write different "strategies" for it. You can think of passport as a piece of framework responsible for authorization.
If it doesn't matter to you, then you can not use it, just make a middleware.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question