I’ve got a MERN chat app that I’m trying to make for my resume, but a problem that I’m running into is that if I change between my profile page and chat page a couple of times, the Axios request that is sent will not be received by the server. This is somewhat fixed by manually refreshing the page, but doesn’t resolve it happening over time. The initial requests function normally, but over time, my server stops receiving requests from that specific client.
Github repository: GitHub - CardinalCyn/ChatApp
The relevant files should be in the server routes.js, with the check session route, as well as in the client, at the profile page axios request.
app.get("/checkSession",async (req,res)=>{
console.log("checked");
if(req.session.user){
return res.json({loggedIn:true, user:req.session.user});
}
else{
return res.json({loggedIn:false});
}
})
Clientside code:
Axios.defaults.withCredentials=true;
useEffect(()=>{
console.log("checking session");
Axios.get("https://192.168.1.192:5000/checkSession").then((response)=>{
console.log(response);
if(!response.data.loggedIn){
navigate("/");
}
else{
console.log(response.data);
setProfileName(response.data.user.username);
}
}).catch((err)=>{
console.log(err);
})
},[navigate])