This commit is contained in:
2025-08-26 10:27:16 +09:00
parent ee300e2c89
commit 5975c35aaa
28 changed files with 444 additions and 476 deletions

View File

@@ -1,5 +1,5 @@
import axios from "axios";
import { getToken, setToken } from "./token";
import axios from 'axios';
import { getToken, setToken } from './token';
export const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL,
@@ -14,7 +14,7 @@ api.interceptors.request.use((config) => {
return config;
}
if (config.headers && "Authorization" in config.headers) {
if (config.headers && 'Authorization' in config.headers) {
delete config.headers.Authorization;
}
@@ -25,17 +25,12 @@ api.interceptors.response.use(
(res) => res,
(error) => {
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
) {
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"; // 전역 리다이렉트
window.location.href = '/login'; // 전역 리다이렉트
}
return Promise.reject(error);
}
},
);