mongodbexpressjwtbcryptthunderclient

Thunder Client, encrypted password unable to login, Server Error Occurred


I am using Thunder Client for testing backend applicatoipn, I encrypted password and jwt token token generated.

http://localhost:4000/login

When trying to login it gives me message- Status: 500 Internal Server Error

{
  "message": "Server Error Occurred"
}

enter image description here

Login route

app.post('/login', async (req, res, next) => {
    const { email, password } = req.body
    console.log(req.body);
    try {

        const user = await User.findEmail({ email });     
        console.log(user)
        if (!user) {
            return res.status(400).json({ message: "Invalid Credentials, Please registered" });
        }

        const isMatchPassword = await bcrypt.compare(password, user.password)   
        if (!isMatchPassword) {
            return res.status(400).json({ message: "Invalid Credentials, Please registered" });
        }

        delete user.password();
        console.log(user);
        return res.status(200).json({ message: "Login Successfull", user });
    } catch (e) {
        next(e);
    }
});

Try to login with different credentials but problem is the same.


Solution

  • Just write

    delete user.password
    

    It directly solve your problem