2026-03-23 14:39:57 -07:00
|
|
|
// src/api/axios.js or similar
|
2026-03-27 14:06:50 -07:00
|
|
|
import axios from "axios";
|
|
|
|
|
import router from "@/router";
|
2026-03-23 14:39:57 -07:00
|
|
|
|
|
|
|
|
const apiClient = axios.create({
|
2026-03-27 14:06:50 -07:00
|
|
|
baseURL: "/api",
|
|
|
|
|
withCredentials: true,
|
2026-03-23 14:39:57 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Response interceptor to catch auth failures
|
|
|
|
|
apiClient.interceptors.response.use(
|
2026-03-27 14:06:50 -07:00
|
|
|
(response) => response,
|
|
|
|
|
(error) => {
|
|
|
|
|
if (error.response && error.response.status === 401) {
|
|
|
|
|
// Session expired or not authenticated
|
|
|
|
|
router.push("/login");
|
|
|
|
|
}
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
},
|
2026-03-23 14:39:57 -07:00
|
|
|
);
|
|
|
|
|
apiClient.isAuthenticated = () => {
|
|
|
|
|
return true;
|
2026-03-27 14:06:50 -07:00
|
|
|
};
|
2026-03-23 14:39:57 -07:00
|
|
|
export default apiClient;
|