getting correct mark with correct message i want crros mark
for the following code i am getting same(positive sign in toast message with coreect message why so plx check it once..
const navigate=useNavigate();
const onFinish = async(values)=>{
try {
const response= await axios.post('/api/user/login',values);
if(response.data.success)
{
toast.success(response.data.message);
toast("Redirecting to home page.");
localStorage.setItem("token",response.data.data);
navigate("/");
}
else{
toast.success(response.data.message);
}
} catch (error) {
toast.error("something went wrong");
}
}
printing toast message
try {
const user = await User.findOne({email:req.body.email});
{
if(!user)
{
return res
.status(200)
.send({message:"User does not exist",success:false});
}
const isMatach=await bcrypt.compare(req.body.password,user.password);
//req.body.password->entered password
//user.password->encrypted password from db
if(!isMatach)
{
return res
.status(200)
.send({message:"Password in incorrect",success:false});
}
else{
const token= jwt.sign({id:user._id},process.env.JWT_SECRET,{expiresIn:"1d"});
//prcess varible //validation time
res
.status(200)
.send({message:"Login successful",success:true,data:token});
}
}
} catch (error) {
console.log(error);
res
.status(500)
.send({message:"error in login",success:false,error});
}
})
I was trying to get a taost message with, i am getting the correct message but with the wrong mark of postive every time even in negative case.