From 8529cc6acea4ceaa30bcf63a67283769cd5ea86c Mon Sep 17 00:00:00 2001 From: Anshv784 Date: Sun, 7 Sep 2025 22:18:48 +0530 Subject: [PATCH 1/2] Fix React Docker blank screen --- client/package.json | 2 +- client/src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/package.json b/client/package.json index fb112814..d62a4dd8 100644 --- a/client/package.json +++ b/client/package.json @@ -2,7 +2,7 @@ "name": "client", "version": "0.1.0", "private": true, - "homepage": "/BlogApp/Client", + "homepage": "/", "dependencies": { "@emotion/react": "^11.9.0", "@emotion/styled": "^11.8.1", diff --git a/client/src/index.js b/client/src/index.js index 922d5a57..a77935ac 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -9,7 +9,7 @@ import { store } from './store'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( - + From f1a0242f2ae1e8a173066c666a0d2392cc928ac4 Mon Sep 17 00:00:00 2001 From: Anshv784 Date: Sun, 7 Sep 2025 22:30:31 +0530 Subject: [PATCH 2/2] Add salt to password hashing in signUp and improve security. Fixes #49 --- server/controller/user-contoller.js | 95 +++++++++++++++-------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/server/controller/user-contoller.js b/server/controller/user-contoller.js index d218dd82..d8b0362a 100644 --- a/server/controller/user-contoller.js +++ b/server/controller/user-contoller.js @@ -1,71 +1,74 @@ const User = require("../model/User"); const bcrypt = require("bcryptjs"); -const getAllUser = async(req,res,next) =>{ +const getAllUser = async (req, res, next) => { let users; - try{ + try { users = await User.find(); } - catch(err){ + catch (err) { console.log(err); } - if(!users){ - return res.status(404).json({ message : "users are not found"}) + if (!users) { + return res.status(404).json({ message: "users are not found" }) } - return res.status(200).json({users}); + return res.status(200).json({ users }); } -const signUp = async(req,res,next) =>{ - const { name , email , password } = req.body; - - let existingUser; - - try{ - existingUser = await User.findOne({email}) - }catch(err){ - console.log(err); - } - - if(existingUser){ - return res.status(400).json({message : "User is already exists!"}) - } - const hashedPassword = bcrypt.hashSync(password); - const user = new User({ - name,email, - password: hashedPassword, - blogs: [] - }); - - try{ - user.save(); - return res.status(201).json({ user }) - } - catch(e){console.log(e);} +const signUp = async (req, res, next) => { + const { name, email, password } = req.body; + + let existingUser; + + try { + existingUser = await User.findOne({ email }) + } catch (err) { + console.log(err); + } + + if (existingUser) { + return res.status(400).json({ message: "User is already exists!" }) + } + // Generate salt + const salt = bcrypt.genSaltSync(10); + const hashedPassword = bcrypt.hashSync(password, salt); + + const user = new User({ + name, email, + password: hashedPassword, + blogs: [] + }); + + try { + await user.save(); + return res.status(201).json({ user }) + } + catch (e) { console.log(e); } } -const logIn = async(req,res,next) => { - const {email , password} = req.body; - +const logIn = async (req, res, next) => { + const { email, password } = req.body; + let existingUser; - try{ - existingUser = await User.findOne({email}) - }catch(err){ - console.log(err); + try { + existingUser = await User.findOne({ email }) + } catch (err) { + console.log(err); } - if(!existingUser){ - return res.status(404).json({message : "User is not found"}) + if (!existingUser) { + return res.status(404).json({ message: "User is not found" }) } - const isPasswordCorrect = bcrypt.compareSync(password,existingUser.password); + const isPasswordCorrect = bcrypt.compareSync(password, existingUser.password); - if(!isPasswordCorrect){ - return res.status(400).json({message: "Incorrect Password!"}); + if (!isPasswordCorrect) { + return res.status(400).json({ message: "Incorrect Password!" }); } - return res.status(200).json({user: existingUser}); + return res.status(200).json({ user: existingUser }); } -module.exports = { getAllUser, signUp , logIn}; \ No newline at end of file +module.exports = { getAllUser, signUp, logIn }; \ No newline at end of file