Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcrypt.compare() Shows "data and hash arguments required" while testing the loginUser in Controller #2

Open
darshanjoshi16 opened this issue Jul 21, 2022 · 1 comment

Comments

@darshanjoshi16
Copy link

` export const loginUser = async(req,res)=>{

const {username,password} = req.body;

try 
{
    const user = UserModel.findOne({username:username})
   
    if(user)
    {
        const validity = await bcrypt.compare(password,user.password)

        validity? res.status(200).json(user): res.status(400).json("Wrong Password")
        

        
    }
    else
    {
        res.status(404).json("User does not exist");
    }
} 
catch (error) 
{
    res.status(500).json({message: error.message});
}

}`

This is the loginUser function..

while testing on thunderclient I am getting below error

image

I tried to check if anything is null because I have seen on on Stack Overflow. When I tried to get req.body.password as response which is passed through the Http request body. it is working but for the user.password which is stored in the database, it is showing the null. so it is where the problem but I cant figure out why it is happening?

Can Anybody Help? Thanks in advance

@nilay-2
Copy link

nilay-2 commented Aug 13, 2023

The above login feature is working fine. I am able to access the user.password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants