how to fix?, password is 123456 is same but is not working to compare.
I have checked that they are all correct.
//const bcrypt = require('bcrypt')
const auth_signin_email = async (req, res) => {
const email = req.body.email;
const password = req.body.password;
if (!email || !password) {
res.status(400)
res.json({message: 'Email invaild'})
};
//sequelize mysql
oldData = await auth.findOne({
where: {email: email}
})
// check oldData == null
if (oldData == null) {
res.json({messages: 'Not found Email, Please Try again'})
};
/*password is 123456*/
bcrypt.compare(password, oldData.password, function (err, isLogged) {
//this False
if (isLogged) {
const token = jwt.sign({data: oldData}, secret, {expiresIn: '12h',
algorithm:'PS384'});
res.json({token: token})
} else {
res.status(400)
res.json({message: 'Wrong Email or Password'})
}
})
}
password = 123456
oldData.password = hash of 123456
bcrypt.compare(password, oldData.password, function (err, isLogged) {
//this False
if (isLogged) {
const token = jwt.sign({data: oldData}, secret, {expiresIn: '12h',
algorithm:'PS384'});
res.json({token: token})
} else {
res.status(400)
res.json({message: 'Wrong Email or Password'})
}
})