Spaces:
Runtime error
Runtime error
Download frontend/src/lib/api.ts from Anish530/ATLAS-Backend: direct link, hf CLI and curl.
- Browser
- Download file 567 Bytes
-
https://huggingface.co/spaces/Anish530/ATLAS-Backend/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/Anish530/ATLAS-Backend/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/Anish530/ATLAS-Backend/resolve/main/frontend/src/lib/api.ts
567 Bytes
| import axios from 'axios'; | |
| import { useAuthStore } from '../store/auth'; | |
| export const api = axios.create({ | |
| baseURL: import.meta.env.VITE_API_URL || 'http://localhost:8000', | |
| }); | |
| api.interceptors.request.use((config) => { | |
| const token = useAuthStore.getState().token; | |
| if (token) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| return config; | |
| }); | |
| api.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| if (error.response?.status === 401) { | |
| useAuthStore.getState().logout(); | |
| } | |
| return Promise.reject(error); | |
| } | |
| ); | |