I have a basic MERN app in production with a login system that always runs into either an ERR_CONNECTION_RESET or an ERR_CONNECTION_REFUSED AxiosError when first attempting to login after what it seems to be a "long time", usually a day. If I press the login button again right after then it logs in anyway without an issue, and from then keeps working throughout the day. It obviously doesn't happen on my machine, as per usual.
The Axios call on the frontend:
const getData = useCallback(async (path, setData) => {
Axios.get(`${apiUrl}/api${path}`, { withCredentials: true })
.then(res => setData(res.data))
.catch(err => console.log(err))
},
[]
)
While the handling of the call on the backend:
async function handleLogin(req, res) {
const loginData = req.body;
const username = loginData.username;
const password = loginData.password;
const userData = await getData(undefined, username, password);
const cookies = getCookies(userData);
const sessionEnd = new Date(Date.now() + ( 1000 * 60 * 60 * 24 ));
const cookieOptions = {expires: sessionEnd, httpOnly: false};
res.cookie("cookies", cookies, cookieOptions).status(200).send(userData);
}
So what could be the cause of this strange bug?