diff --git a/server/controllers/auth.js b/server/controllers/auth.js index 10bf081..6db4baa 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -18,7 +18,7 @@ export const register = async (req, res) => { userName, firstName, lastName, - email, + email: email.toLowerCase(), password: passwordHash, }); diff --git a/server/controllers/user.js b/server/controllers/user.js index 509b802..30b9a2e 100644 --- a/server/controllers/user.js +++ b/server/controllers/user.js @@ -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) { diff --git a/server/routes/user.js b/server/routes/user.js index fbd9d56..ddaa8c5 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -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);