change function and design page doctors & signin & signup & home & specialties & helper

This commit is contained in:
Ehsan
2025-05-21 16:44:34 +03:30
parent c8c217e286
commit 6c7709c342
13 changed files with 96 additions and 86 deletions
+4 -26
View File
@@ -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;
}
);