Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question