Seems to be related with the following issues:
Preventing the page from reloading and routing it back to the page that causes the problem has the exact same effect.
useBeforeunload((event: any) => {
event.preventDefault();
router.push("/login");
});
Still looking into it. 