From cc8c445a4e282233c61afd9b09254a0408acaf7b Mon Sep 17 00:00:00 2001 From: Chaitanya-chute Date: Fri, 15 May 2026 12:34:59 +0530 Subject: [PATCH 1/3] fix: install dev deps before build in Dockerfile.prod --- Dockerfile.prod | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index 6fb1532..fa8a6c9 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -7,12 +7,12 @@ WORKDIR /app # Copy package.json COPY package.json . -# Install production dependencies using Yarn -RUN npm install --production +# Install dependencies (dev deps needed for the build step) +RUN npm install # Copy the rest of the application files COPY . . -# Build the frontend using Yarn +# Build the frontend RUN npm run build # Stage 2: Serve the application with Nginx From 6f39079d3cf446c4280c2012d870efd7e02658cf Mon Sep 17 00:00:00 2001 From: Chaitanya-chute Date: Fri, 15 May 2026 12:42:52 +0530 Subject: [PATCH 2/3] Fixed login redirect to a valid route --- src/pages/Login/Login.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Login/Login.tsx b/src/pages/Login/Login.tsx index d6f21a7..e77ee3b 100644 --- a/src/pages/Login/Login.tsx +++ b/src/pages/Login/Login.tsx @@ -34,7 +34,7 @@ const Login: React.FC = () => { setMessage(response.data.message); if (response.data.message === 'Login successful') { - navigate("/home"); + navigate("/"); } } catch (error: any) { setMessage(error.response?.data?.message || "Something went wrong"); From 23f1147b85c282510e181f8e9e6403bd4ddea2e7 Mon Sep 17 00:00:00 2001 From: Chaitanya-chute Date: Fri, 15 May 2026 13:03:42 +0530 Subject: [PATCH 3/3] fix: handle duplicate username on signup --- backend/routes/auth.js | 14 ++++++++++---- spec/auth.routes.spec.cjs | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/routes/auth.js b/backend/routes/auth.js index e26c7a9..da60aff 100644 --- a/backend/routes/auth.js +++ b/backend/routes/auth.js @@ -9,15 +9,21 @@ router.post("/signup", async (req, res) => { const { username, email, password } = req.body; try { - const existingUser = await User.findOne( {email} ); + const existingUser = await User.findOne({ + $or: [{ email }, { username }], + }); if (existingUser) - return res.status(400).json( {message: 'User already exists'} ); + return res.status(400).json({ message: 'User already exists' }); - const newUser = new User( {username, email, password} ); + const newUser = new User({ username, email, password }); await newUser.save(); - res.status(201).json( {message: 'User created successfully'} ); + res.status(201).json({ message: 'User created successfully' }); } catch (err) { + if (err && err.code === 11000) { + return res.status(400).json({ message: 'User already exists' }); + } + res.status(500).json({ message: 'Error creating user', error: err.message }); } }); diff --git a/spec/auth.routes.spec.cjs b/spec/auth.routes.spec.cjs index c5ac003..e8662ce 100644 --- a/spec/auth.routes.spec.cjs +++ b/spec/auth.routes.spec.cjs @@ -57,6 +57,15 @@ describe('Auth Routes', () => { expect(res.body.message).toBe('User already exists'); }); + it('should not sign up a user with existing username', async () => { + await new User({ username: 'testuser', email: 'test@example.com', password: 'password123' }).save(); + const res = await request(app) + .post('/auth/signup') + .send({ username: 'testuser', email: 'test2@example.com', password: 'password456' }); + expect(res.status).toBe(400); + expect(res.body.message).toBe('User already exists'); + }); + it('should login a user with correct credentials', async () => { await request(app) .post('/auth/signup')