This is my get function
const navigate = useNavigate();
const [userData,setUserData] = useState({});
useEffect(()=>{
if(Cookies.get('auth') !== 'AUTHENTICATED'){
navigate('/');
}
$(".navbar").css('display','block');
let getUser = async () => {
const result = await axios.get(`http://localhost:3000/get/user${Cookies.get('id')}`);
setUserData(result.data);
console.log(result.data);
}
getUser();
},[]);
This is my get Route
app.get('/get/user:id', async (req,res) => {
var id = parseInt(req.params.id);
console.log(id);
const result = db.query('SELECT * FROM users WHERE id = $1',[id]);
console.log(result.rows);
});
I am having trouble with executing the query as the query is returning undefined value.
This is my output
This is my Database
I am getting the id as a string from path variable but even after using parseInt()
it is not working
EDIT: I have tried to modify the endpoint as ‘/user/:id’ but it still does not work, still returns undefined.