Spaces:
Configuration error
Configuration error
Download frontend/lib/api.ts from MandyDeep/social-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 675 Bytes
-
https://huggingface.co/spaces/MandyDeep/social-dashboard/resolve/main/frontend/lib/api.ts
- Command line
-
hf download hf://spaces/MandyDeep/social-dashboard/frontend/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/MandyDeep/social-dashboard/resolve/main/frontend/lib/api.ts
675 Bytes
| import axios from "axios"; | |
| const API_URL = process.env.NEXT_PUBLIC_API_URL || ""; | |
| export const api = axios.create({ | |
| baseURL: API_URL, | |
| headers: { "Content-Type": "application/json" }, | |
| }); | |
| api.interceptors.request.use((config) => { | |
| const token = typeof window !== "undefined" ? localStorage.getItem("token") : ""; | |
| if (token) config.headers.Authorization = `Bearer ${token}`; | |
| return config; | |
| }); | |
| api.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| if (error.response?.status === 401 && typeof window !== "undefined") { | |
| localStorage.removeItem("token"); | |
| window.location.href = "/login"; | |
| } | |
| return Promise.reject(error); | |
| } | |
| ); | |