diff --git a/server/controllers/user.js b/server/controllers/user.js index c8be843..509b802 100644 --- a/server/controllers/user.js +++ b/server/controllers/user.js @@ -24,10 +24,14 @@ export const getUserById = async (req, res) => { export const getUserByEmailOrUsername = async (req, res) => { try { - const { emailOrUsername } = req.params; + const { email, username } = req.body; + + const conditions = []; + if (email) conditions.push({ email }); + if (username) conditions.push({ userName: username }); const user = await UserModel.findOne({ - $or: [{ email: emailOrUsername }, { userName: emailOrUsername }], + $or: conditions, }); if (!user) { diff --git a/server/routes/user.js b/server/routes/user.js index 42fe6eb..fbd9d56 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -13,7 +13,7 @@ import { const router = express.Router(); -router.get("/search/:emailOrUsername", getUserByEmailOrUsername); +router.post("/search", getUserByEmailOrUsername); router.get("/:userId", getUserById); router.get("/:userId/friends", getUserFriends);