add validation and basic api && change design sidebar

This commit is contained in:
ehsanahmadi456
2025-04-01 15:38:07 +03:30
parent b09957f97c
commit 13a9de2438
8 changed files with 41 additions and 12 deletions
+13 -4
View File
@@ -13,8 +13,18 @@ const api = axios.create({
api.interceptors.request.use(
(request) => {
if (cookies.get("token")) {
request.headers.authorization = `Bearer ${cookies.get("token")}`;
const token = cookies.get("token");
const isLoginPage = window.location.pathname === "/login";
if (!token) {
if (!isLoginPage) {
window.location.pathname = "/login";
}
} else {
if (isLoginPage) {
window.location.pathname = "/";
}
request.headers.authorization = `Bearer ${token}`;
}
return request;
},
@@ -26,10 +36,9 @@ api.interceptors.response.use(
return response.data;
},
(error) => {
console.log(error);
if (error.data.status === 400) {
cookies.remove("token", { path: "/" });
window.location.reload();
window.location.pathname = "/login";
} else {
}
}