This commit is contained in:
2025-08-22 17:31:25 +09:00
parent 122d639cfb
commit 75e05dc5ab
24 changed files with 2203 additions and 56 deletions

28
web/src/lib/api.ts Normal file
View File

@@ -0,0 +1,28 @@
import axios from "axios";
import { getToken, setToken } from "./token";
export const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
});
api.interceptors.request.use((config) => {
const t = getToken();
if (t) {
config.headers = config.headers ?? {};
config.headers.Authorization = `Bearer ${t}`;
}
return config;
});
api.interceptors.response.use(
(res) => res,
(error) => {
if (error?.response?.status === 401 && typeof window !== "undefined") {
setToken(null); // 토큰 파기
window.location.href = "/login"; // 전역 리다이렉트
}
return Promise.reject(error);
}
);