Skip to content

Commit

Permalink
prevent dupe user
Browse files Browse the repository at this point in the history
  • Loading branch information
phucd5 committed Oct 28, 2023
1 parent 975f74f commit 7c2e84a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export const register = async (req, res) => {
try {
const { userName, password, email, firstName, lastName } = req.body;

const existingUser = await UserModel.findOne({ userName });
if (existingUser) {
return handleBadRequest(
res,
"Username already found. Please try again."
);
}

const salt = await bcrypt.genSalt(10);
const passwordHash = await bcrypt.hash(password, salt);

Expand Down

0 comments on commit 7c2e84a

Please sign in to comment.