Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Functionality #77

Open
NouraldinS opened this issue Apr 25, 2018 · 0 comments
Open

Split Functionality #77

NouraldinS opened this issue Apr 25, 2018 · 0 comments

Comments

@NouraldinS
Copy link

const dbConnection = require('../db_connection');
const bcrypt = require('bcrypt');
const getUserData = (email,password1,cb)=>{
const sql = {
text: 'SELECT name,id,role,password FROM users WHERE email = $1',
values:[email]
}
dbConnection.query(sql,(err,res)=>{
if (err) return cb(err)
console.log(res.rows[0].password,'ramy');
let hashPassword=res.rows[0].password
bcrypt.compare(password1, hashPassword, function(error, result) {
if (error) {
return cb({error,type:'database error'});
}
else if(result==true){
return cb(null,res.rows[0])
}
else {
return cb({error,type:'password not match'});
}
});
});
}
module.exports=getUserData;

check.js lies in queries folder, which is - by name - is made to hold database queries. Do not check for your user and password inside the query, just do it when you're calling the query. I know it all works the same, but one is more readable than the other. So please consider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant