akashyap2013 / MERN_Login_App_with_ResetEmail

In this project, we are going to create the MERN Login App with Reset Email Feature.
234 stars 162 forks source link

Get User API not working please help me, It return as error: "Cannot Find User Data" #12

Open jayarajito opened 3 months ago

jayarajito commented 3 months ago

/* GET: http://localhost:8080/api/user/example123 /

export async function getUser(req, res) { //res.json("Get User Route"); const { username } = req.params; console.log("I am from getUserController", username);

try { if (!username) return res.status(501).send({ error: "Invalid Username" }); UserModel.findOne({ username }, function (err, user) { if (err) return res.status(500).send({ err }); if (!user) return res.status(501).send({ error: "Couldn't Find the User" }); return res.status(201).send(user); }); } catch (error) { return res.status(404).send({ error: "Cannot Find User Data" }); } }