Files
Stirling-PDF/frontend/src/proprietary/services/apiClientSetup.ts
James Brunton d2b38ef4b8 Restructure frontend code to allow for extensions (#4721)
# Description of Changes
Move frontend code into `core` folder and add infrastructure for
`proprietary` folder to include premium, non-OSS features
2025-10-28 10:29:36 +00:00

30 lines
809 B
TypeScript

import { AxiosInstance } from 'axios';
function getJwtTokenFromStorage(): string | null {
try {
return localStorage.getItem('stirling_jwt');
} catch (error) {
console.error('[API Client] Failed to read JWT from localStorage:', error);
return null;
}
}
export function setupApiInterceptors(client: AxiosInstance): void {
// Install request interceptor to add JWT token
client.interceptors.request.use(
(config) => {
const jwtToken = getJwtTokenFromStorage();
if (jwtToken && !config.headers.Authorization) {
config.headers.Authorization = `Bearer ${jwtToken}`;
console.debug('[API Client] Added JWT token from localStorage to Authorization header');
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
}