auth - when creds were wrong, fixed

This commit is contained in:
2025-07-03 23:21:40 +05:30
parent 54f80db08a
commit 64dc43daa7
4 changed files with 113 additions and 69 deletions

View File

@@ -8,7 +8,10 @@ async function throwIfResNotOk(res: Response) {
if (res.status === 401 || res.status === 403) {
localStorage.removeItem("token");
window.location.href = "/auth"; // 👈 Redirect on invalid/expired token
if (!window.location.pathname.startsWith("/auth")) {
window.location.href = "/auth";
throw new Error(`${res.status}: Unauthorized`);
}
return;
}
throw new Error(`${res.status}: ${text}`);