Skip to content

Split Functionality #77

Description

@NouraldinS

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions