From ef2eb95105aec383fc27370a3415e06497049c1e Mon Sep 17 00:00:00 2001 From: Shrikant Anand Surwase <97949621+Shrikant-Surwase@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:51:51 +0530 Subject: [PATCH 1/2] Update user-controller.js We need to check first if username is present or not. --- Blog-Website/server/controller/user-controller.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Blog-Website/server/controller/user-controller.js b/Blog-Website/server/controller/user-controller.js index 8ad08559..bbde0ac7 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}); + 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 +} From 3057ca6de2259eb4905e277766323cb3515dda46 Mon Sep 17 00:00:00 2001 From: Shrikant Anand Surwase <97949621+Shrikant-Surwase@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:54:46 +0530 Subject: [PATCH 2/2] Update user-controller.js --- Blog-Website/server/controller/user-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blog-Website/server/controller/user-controller.js b/Blog-Website/server/controller/user-controller.js index bbde0ac7..8d82b728 100644 --- a/Blog-Website/server/controller/user-controller.js +++ b/Blog-Website/server/controller/user-controller.js @@ -16,7 +16,7 @@ export const singupUser = async (request, response) => { 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}); + const check = await User.findOne({username: request.body.username}); if(check){ return response.status(500).json({message:"Username already Used"}); }