- Upgrade Nx 22.1.1 → 22.6.3 and all patch/minor dependencies - Restructure shared libs: move business logic from utils to service - Consolidate shadcn-ui into ui lib with atomic design pattern - Fix container centering for landing app (Tailwind v4 compatibility) - Fix button styling by updating @source directive in globals.css - Fix SiCss3 → SiCss rename in react-icons 5.6 - Fix duplicate useSession export conflict - Remove dead code, comments, and unused files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import axios from 'axios';
|
|
import { useAuthStore } from '../hooks/auth';
|
|
|
|
const BACKOFFICE_API_URL = 'https://api.hackathon.imphnen.dev/api/v1';
|
|
|
|
export const backofficeApi = axios.create({
|
|
baseURL: BACKOFFICE_API_URL,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
backofficeApi.interceptors.request.use(
|
|
(config) => {
|
|
const { session } = useAuthStore.getState();
|
|
if (session?.token?.access_token) {
|
|
config.headers.Authorization = `Bearer ${session.token.access_token}`;
|
|
}
|
|
return config;
|
|
},
|
|
(error) => {
|
|
return Promise.reject(new Error(error.message || 'Request failed'));
|
|
}
|
|
);
|
|
|
|
backofficeApi.interceptors.response.use(
|
|
(response) => response,
|
|
(error) => {
|
|
if (error.response?.status === 401) {
|
|
const isAuthPage =
|
|
globalThis.window !== undefined &&
|
|
globalThis.location.pathname.startsWith('/auth');
|
|
|
|
if (!isAuthPage) {
|
|
useAuthStore.getState().clearSession();
|
|
if (globalThis.window !== undefined) {
|
|
globalThis.location.href = '/auth/login';
|
|
}
|
|
}
|
|
}
|
|
|
|
const backendMsg = error?.response?.data?.message;
|
|
if (backendMsg && typeof backendMsg === 'string') {
|
|
return Promise.reject(new Error(backendMsg));
|
|
}
|
|
|
|
return Promise.reject(new Error(error.message || 'An error occurred'));
|
|
}
|
|
);
|
|
|
|
export interface BackofficeApiResponse<T> {
|
|
data: T;
|
|
message: string;
|
|
}
|