Spaces:
Sleeping
Sleeping
Download frontend/src/lib/api.ts from tech-ties/filezkit-backend: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/tech-ties/filezkit-backend/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/frontend/src/lib/api.ts
982 Bytes
| import axios from "axios"; | |
| const TOKEN_KEY = "pdfflow_token"; | |
| export const api = axios.create({ | |
| baseURL: process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000", | |
| }); | |
| // Attach JWT token to every request | |
| api.interceptors.request.use((config) => { | |
| if (typeof window !== "undefined") { | |
| const token = localStorage.getItem(TOKEN_KEY); | |
| if (token) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| } | |
| return config; | |
| }); | |
| // Handle 401 responses — clear stale token only. | |
| // No-login model: tools work without auth, so a 401 must NOT force a redirect | |
| // to signin. We just drop any stale/expired token and let the caller handle | |
| // the error inline (e.g. an account-only page can prompt to sign in). | |
| api.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| if ( | |
| error.response?.status === 401 && | |
| typeof window !== "undefined" | |
| ) { | |
| localStorage.removeItem(TOKEN_KEY); | |
| } | |
| return Promise.reject(error); | |
| } | |
| ); |