Reputation: 1
hello everyone getting this problem can not login getting server error which is in catch part checked credential and evryhting is okay getting the data in req.body but getting nothing when console log userr can anyone plz tell me what can be the problem with this
const login = async (req, res) =>{ try {
const {email, password} = req.body;
console.log(req.body);
const userExists = await findOne({email});
console.log(userExists);
if (!userExist) {
return res.status(400).json({message: "invalid credentials"});
}
const userr = await bcrypt.compare(password, userExists.password);
if (userr) {
res.status(200).json({
msg:"login succesfull",
token: await userExists.generateToken(),
userId: userExists._id.toString(),});
}
else{
res.status(401).json({msg:"invalid email or password"});
}
} catch (error) {
res.status(500).json({msg:"server error "});
}
}
i have created registration also which is working fine the data is being stored in database, but the login functionality is not working .
Upvotes: -2
Views: 40
Reputation: 1
if the credentials are correct check once by correcting the typo error and try "userExist" to "userExists" in if block
Upvotes: 0