I am currently working on a minimalist website using pure JavaScript and the fetch API to interact with a backend powered by Node.js and Express.js. Once the user logs in, a session cookie is generated.
The issue I'm encountering is related to redirecting to a login page if the session turns out to be invalid for any client request. I have attempted to handle this from the server-side by implementing:
res.status(301).redirect("/login.html");
Despite seeing the redirection occur in the developer tools network tab of the browser and observing the download of the 'login.html' file, it appears that the actual navigation to the page does not happen. Could there be something crucial that I am overlooking?
Is there a more efficient way to approach this dilemma? While one option would involve performing an additional check on the frontend before each request and subsequently executing the redirect, I prefer to avoid such verbosity in my code if possible...