|
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.
w6_Stop_Go_Cont/src/database/queries/check.js
Lines 1 to 30 in 3cf9b40
check.jslies inqueriesfolder, 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.