This commit is contained in:
2025-08-25 17:23:25 +09:00
parent 75e05dc5ab
commit 8ac669cabb
10 changed files with 337 additions and 30 deletions

View File

@@ -10,6 +10,12 @@ api.interceptors.request.use((config) => {
if (t) {
config.headers = config.headers ?? {};
config.headers.Authorization = `Bearer ${t}`;
return config;
}
if (config.headers && "Authorization" in config.headers) {
delete config.headers.Authorization;
}
return config;
@@ -18,7 +24,14 @@ api.interceptors.request.use((config) => {
api.interceptors.response.use(
(res) => res,
(error) => {
if (error?.response?.status === 401 && typeof window !== "undefined") {
const url: string | undefined = error?.config?.url;
const isAuthRoute =
url?.includes("/auth/login") || url?.includes("/auth/signup");
if (
error?.response?.status === 401 &&
typeof window !== "undefined" &&
!isAuthRoute
) {
setToken(null); // 토큰 파기
window.location.href = "/login"; // 전역 리다이렉트
}