fe j
This commit is contained in:
@@ -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"; // 전역 리다이렉트
|
||||
}
|
||||
|
Reference in New Issue
Block a user