diff --git a/Blog-Website/server/controller/user-controller.js b/Blog-Website/server/controller/user-controller.js index 8ad08559..8d82b728 100644 --- a/Blog-Website/server/controller/user-controller.js +++ b/Blog-Website/server/controller/user-controller.js @@ -14,7 +14,12 @@ export const singupUser = async (request, response) => { const hashedPassword = await bcrypt.hash(request.body.password, 10); const user = { username: request.body.username, name: request.body.name, password: hashedPassword } - + //we need to first check if user already present or not if present then we have to throw an error otherwise we have + //to save it's details + const check = await User.findOne({username: request.body.username}); + if(check){ + return response.status(500).json({message:"Username already Used"}); + } const newUser = new User(user); await newUser.save(); @@ -55,4 +60,4 @@ export const logoutUser = async (request, response) => { await Token.deleteOne({ token: token }); response.status(204).json({ msg: 'logout successfull' }); -} \ No newline at end of file +}