From 64af5185361640a0f865b8dab6418ad1d03e2cab Mon Sep 17 00:00:00 2001 From: mr-loop-1 <loopolecreator1@gmail.com> Date: Thu, 5 Sep 2024 10:04:39 +0530 Subject: [PATCH] moved user exist error to email field --- backend/src/controllers/auth.controller.js | 2 +- frontend/src/scenes/login/CreateAccountPage.jsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/controllers/auth.controller.js b/backend/src/controllers/auth.controller.js index 9ab72979..e251b3d1 100644 --- a/backend/src/controllers/auth.controller.js +++ b/backend/src/controllers/auth.controller.js @@ -11,7 +11,7 @@ const register = async (req, res) => { try { const { username, email, password } = req.body; const existingUser = await User.findOne({ where: { email } }); - if (existingUser) return res.status(400).json({ error: "User already exists" }); + if (existingUser) return res.status(400).json({ error: "Email already exists" }); const hashedPassword = await bcrypt.hash(password, 10); const newUser = await User.create({ username, email, password: hashedPassword }); diff --git a/frontend/src/scenes/login/CreateAccountPage.jsx b/frontend/src/scenes/login/CreateAccountPage.jsx index f6ac6bb7..01972f01 100644 --- a/frontend/src/scenes/login/CreateAccountPage.jsx +++ b/frontend/src/scenes/login/CreateAccountPage.jsx @@ -55,8 +55,8 @@ function CreateAccountPage() { navigate('/'); } catch (error) { if (error.response && error.response.data) { - if (error.response.data.error === 'User already exists') { - setError('User already exists'); + if (error.response.data.error === 'Email already exists') { + setError('Email already exists'); } else { setError('An error occurred. Please try again.'); } @@ -82,7 +82,6 @@ function CreateAccountPage() { onChange={handleInputChange} placeholder="Enter your username" /> - {error && <div className="error-message">{error}</div>} </div> <div className="form-group"> @@ -98,6 +97,7 @@ function CreateAccountPage() { onChange={handleInputChange} placeholder="Enter your email" /> + {error && <div className="error-message">{error}</div>} </div> <div className="form-group">