prtr
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user