Skip to content

Commit

Permalink
chore : 리프레쉬토큰 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuna committed Aug 3, 2024
1 parent 1461a04 commit 8e1cba5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
34 changes: 18 additions & 16 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,32 @@ refreshInstance.interceptors.request.use(
},
(error: AxiosError) => Promise.reject(error)
);

instance.interceptors.response.use(
(response) => response,
async (error: AxiosError) => {
if (axios.isAxiosError(error) && error.response) {
const { status } = error.response;
if (status === 401) {
const refreshToken = cookie.get("refresh_token");
if (refreshToken) {
try {
await axios
.put(`${BASEURL}/admin/refresh`, null, {
headers: {
"X-Refresh-Token": `${refreshToken}`,
},
})
.then((response) => {
const data = response.data;
cookie.set("access_token", data.access_token);
cookie.set("refresh_token", data.refresh_token);
});
} catch (refreshError) {
return Promise.reject(refreshError);
try {
await axios
.put(`${BASEURL}/admin/refresh`, null, {
headers: {
"X-Refresh-Token": `${refreshToken}`,
},
})
.then((response) => {
const data = response.data;
cookie.set("access_token", data.access_token);
cookie.set("refresh_token", data.refresh_token);
})
.catch(() => {
window.location.href = "login";
});
{
}
} catch (refreshError) {
return Promise.reject(refreshError);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/hook/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const apiError = () => {
alert("400 잘못된 요청입니다");
};

const handle401: ErrorHandler = () => {
router.push("login");
};
const handle401: ErrorHandler = () => {};

const handle403: ErrorHandler = () => {
alert("403 권한이 없습니다");
Expand Down

0 comments on commit 8e1cba5

Please sign in to comment.