- Fix GPS map links always sending literal "latitude"/"longitude" strings instead of actual coordinates in openLocation/Content.js - Add api.clinic-pro.ir to next.config.js remotePatterns so production images load correctly - Fix appointment page: await params and getStateInfo (Next.js 15 pattern) - Enable 401 handling in api.js: clear cookies and redirect to /login - Move OAuth client_secret to server-side API routes (/api/auth/token, /api/auth/refresh) so it is never bundled into client-side JavaScript - Update SendReq, SubmitData, ButtonSendData to call API routes instead of directly sending client_secret from the browser - Update docker-compose.yml to use server-only CLIENT_SECRET env var - Remove debug console.log from clinic doctors list component Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import axios from "axios";
|
|
import Cookies from "js-cookie";
|
|
import "react-toastify/dist/ReactToastify.css";
|
|
|
|
const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
|
|
const api = axios.create({
|
|
baseURL: BASE_URL,
|
|
"X-CSRF-Token": "",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
|
|
// اضافه کردن interceptor برای افزودن token به ریکوستهایی که نیاز به احراز هویت دارند
|
|
api.interceptors.request.use(
|
|
(config) => {
|
|
// فقط اگر requireAuth در config تنظیم شده باشد، token اضافه میشود
|
|
if (config.requireAuth) {
|
|
const token = Cookies.get("access_token");
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`;
|
|
}
|
|
}
|
|
return config;
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
api.interceptors.response.use(
|
|
(response) => {
|
|
return response.data;
|
|
},
|
|
(error) => {
|
|
if (error?.response?.status === 401 && typeof window !== "undefined") {
|
|
["access_token", "refresh_token", "uuid", "userInfo"].forEach((key) => {
|
|
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
|
});
|
|
window.location.href = "/login";
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default api;
|