diff --git a/.gitignore b/.gitignore index 889fd38..8d58e11 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ dist/ downloads/ eggs/ .eggs/ -lib/ +/lib/ lib64/ parts/ sdist/ diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts new file mode 100644 index 0000000..f29138e --- /dev/null +++ b/frontend/src/lib/api.ts @@ -0,0 +1,32 @@ +import axios from 'axios'; + +export const api = axios.create({ + baseURL: '/api', // Proxy in vite.config.ts handles this + headers: { + 'Content-Type': 'application/json', + }, +}); + +// Request interceptor to add JWT token +api.interceptors.request.use( + (config) => { + const token = localStorage.getItem('access_token'); + if (token) { + config.headers.Authorization = `Bearer ${token}`; + } + return config; + }, + (error) => Promise.reject(error) +); + +// Response interceptor for error handling +api.interceptors.response.use( + (response) => response, + (error) => { + // Handle 401 (Unauthorized) globally - clear token + if (error.response?.status === 401) { + localStorage.removeItem('access_token'); + } + return Promise.reject(error); + } +); diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts new file mode 100644 index 0000000..e644794 --- /dev/null +++ b/frontend/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +}