add validation and basic api && change design sidebar
This commit is contained in:
+13
-4
@@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user