Skip to content

Commit

Permalink
moved user exist error to email field
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-loop-1 committed Sep 5, 2024
1 parent 95f2674 commit 64af518
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/src/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/scenes/login/CreateAccountPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -82,7 +82,6 @@ function CreateAccountPage() {
onChange={handleInputChange}
placeholder="Enter your username"
/>
{error && <div className="error-message">{error}</div>}
</div>

<div className="form-group">
Expand All @@ -98,6 +97,7 @@ function CreateAccountPage() {
onChange={handleInputChange}
placeholder="Enter your email"
/>
{error && <div className="error-message">{error}</div>}
</div>

<div className="form-group">
Expand Down

0 comments on commit 64af518

Please sign in to comment.