Skip to content

Commit

Permalink
fixed duped email and updated /search route
Browse files Browse the repository at this point in the history
  • Loading branch information
phucd5 committed Oct 28, 2023
1 parent 56b747b commit 17d07f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const register = async (req, res) => {
userName,
firstName,
lastName,
email,
email: email.toLowerCase(),
password: passwordHash,
});

Expand Down
11 changes: 5 additions & 6 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ export const getUserById = async (req, res) => {

export const getUserByEmailOrUsername = async (req, res) => {
try {
const { email, username } = req.body;

const conditions = [];
if (email) conditions.push({ email });
if (username) conditions.push({ userName: username });
const { email, userName } = req.body;

const user = await UserModel.findOne({
$or: conditions,
$or: [
{ email: { $regex: new RegExp(`^${email}$`, "i") } },
{ userName: userName },
],
});

if (!user) {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

const router = express.Router();

router.post("/search", getUserByEmailOrUsername);
router.get("/search", getUserByEmailOrUsername);
router.get("/:userId", getUserById);

router.get("/:userId/friends", getUserFriends);
Expand Down

0 comments on commit 17d07f9

Please sign in to comment.