change function and design page doctors & signin & signup & home & specialties & helper
This commit is contained in:
+4
-26
@@ -1,46 +1,24 @@
|
||||
import axios from "axios";
|
||||
import Cookies from "universal-cookie";
|
||||
import "react-toastify/dist/ReactToastify.css";
|
||||
|
||||
const cookies = new Cookies();
|
||||
const BASE_URL = "https://nobat724.com/";
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${cookies.get("access")}`,
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use(
|
||||
(request) => {
|
||||
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;
|
||||
},
|
||||
(err) => Promise.reject(err)
|
||||
);
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
if (error.data.status === 400) {
|
||||
cookies.remove("token", { path: "/" });
|
||||
window.location.pathname = "/login";
|
||||
} else {
|
||||
}
|
||||
return error;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user