I am creating social media app.
For some reason my route of:
const res = await axios.get(`/users?username=${username}`);
is returning all users
All users endpoint is
/users
I have been debugging for at least 5 hours but I don't know how its mapping from /users?username=${username}
to /users
This is my getUsers API
const getUsers = async (req,res,next)=>{
try {
const users = await User.find();
res.status(200).json(users);
} catch (err) {
next(err);
}
}
This is the route:
//get all user
router.get("/", verifyUser, getUsers);
I haven't defined the following anywhere
/users?username=${username}
I don't know why this route is using my getUsers API. Please help
P.S. this is where it's all happening:
client/src/pages/profile
import "./profile.css";
import Topbar from "../../components/topbar/Topbar";
import Sidebar from "../../components/sidebar/Sidebar";
import Feed from "../../components/feed/Feed";
import Rightbar from "../../components/rightbar/Rightbar";
import {useState, useEffect} from "react"
import axios from "axios";
import { useParams } from "react-router"
export default function Profile() {
const PF = process.env.REACT_APP_PUBLIC_FOLDER
const [user,setUser] = useState({})
const username = useParams().username
useEffect(() => {
const fetchUser = async () => {
const res = await axios.get(`/users?username=${username}`);
setUser(res.data)
}
fetchUser()
},[username])
console.log(user)
return (
<>
<Topbar />
<div className="profile">
<Sidebar />
<div className="profileRight">
<div className="profileRightTop">
<div className="profileCover">
<img
className="profileCoverImg"
src={user.coverPicture || PF+"post/ronaldo.jpg"}
alt=""
/>
<img
className="profileUserImg"
src={user.profilePicture
? PF + user.profilePicture
: PF + "persons/noavatar.png"}
alt=""
/>
</div>
<div className="profileInfo">
<h4 className="profileInfoName">{user.username}</h4>
<span className="profileInfoDesc">{user.desc}</span>
</div>
</div>
<div className="profileRightBottom">
<Feed username={username}/>
<Rightbar user={user}/>
</div>
</div>
</div>
</>
);
}