Skip to content

Commit 28d44f1

Browse files
committed
Merge branch 'dev' of github.com:prgrms-web-devcourse-final-project/WEB2_3_DFBF_FE into feat/159-chat-request-and-cancel
2 parents 0273791 + c6352ef commit 28d44f1

File tree

3 files changed

+28
-45
lines changed

3 files changed

+28
-45
lines changed

dev-dist/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict';
7979
*/
8080
workbox.precacheAndRoute([{
8181
"url": "index.html",
82-
"revision": "0.uiau2f3o4b"
82+
"revision": "0.2ufi9jpmuo"
8383
}], {});
8484
workbox.cleanupOutdatedCaches();
8585
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {

src/apis/auth.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import axios from 'axios';
12
import { axiosInstance } from './axios';
23
import { useAuthStore } from '@/store/authStore';
34

@@ -19,37 +20,21 @@ export const login = async (loginId: string, password: string) => {
1920
// 로그아웃
2021
export const postLogout = async () => {
2122
const { data } = await axiosInstance.post('/auth/logout');
22-
// useAuthStore.getState().logout(); // 전역 상태 초기화
23-
// window.location.href = '/'; // 랜딩 페이지로 이동
2423
return data;
2524
};
2625

2726
// 토큰 재발급
2827
export const reissueToken = async () => {
29-
const { data } = await axiosInstance.post('/auth/token');
30-
console.log('토큰 재발급:', data);
31-
32-
if (data.data === null) return; // AT 토큰이 아직 유효하면 리턴
28+
const { data } = await axios.post('/api/auth/token', {
29+
withCredentials: true,
30+
});
3331

3432
const accessToken = data.data.accessToken; // 새로운 AT
35-
const code = data.code; // 200: 성공, 400: 실패
33+
const code = data.code; // 200: 성공
3634

3735
if (code === 200) {
3836
useAuthStore.getState().setAccessToken(accessToken); // 토큰 전역 상태 저장
3937
console.log('토큰 재발급 성공:', accessToken);
4038
}
41-
42-
if (code === 400) {
43-
// useAuthStore.getState().logout(); // 전역 상태 초기화
44-
console.log('토큰 재발급 실패:', data);
45-
// window.location.href = '/'; // 랜딩 페이지로 이동
46-
}
47-
48-
// 유효하지 않은 토큰
49-
if (code === 401) {
50-
// useAuthStore.getState().logout(); // 전역 상태 초기화
51-
console.log('유효하지 않은 토큰:', data);
52-
// window.location.href = '/'; // 랜딩 페이지로 이동
53-
}
5439
return data;
5540
};

src/apis/axios.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ axiosInstance.interceptors.request.use(
1515
// 토큰이 있으면 요청 헤더에 추가
1616
if (token) {
1717
config.headers.Authorization = `Bearer ${token}`;
18-
console.log('요청 헤더에 Authorization 추가됨:', config.headers);
18+
// console.log('요청 헤더에 Authorization 추가됨:', config.headers);
1919
}
2020
return config;
2121
},
@@ -26,31 +26,29 @@ axiosInstance.interceptors.request.use(
2626
);
2727

2828
// 응답 인터셉터
29-
// axiosInstance.interceptors.response.use(
30-
// (response) => response,
31-
// async (error) => {
32-
// console.log('응답 인터셉터');
33-
// // 응답 에러 처리
34-
// const originalRequest = error.config; // 실패한 요청 정보 저장
35-
// console.log('요청 실패:', originalRequest);
36-
// if (!originalRequest) return Promise.reject(error); // 요청 정보 자체가 아예 없을 경우 종료
29+
axiosInstance.interceptors.response.use(
30+
(response) => response,
31+
async (error) => {
32+
// 응답 에러 처리
33+
const originalRequest = error.config; // 실패한 요청 정보 저장
3734

38-
// // AT 토큰 만료 시
39-
// if (error.response.status === 403 && !originalRequest._retry) {
40-
// originalRequest._retry = true; // 재시도 방지
35+
// AT 토큰 만료 시
36+
if (error.response.status === 401 && !originalRequest._retry) {
37+
originalRequest._retry = true; // 재시도 방지
4138

42-
// console.log('토큰 만료', originalRequest);
43-
// try {
44-
// await reissueToken(); // 토큰 재발급 요청
45-
// return axiosInstance(originalRequest); // 원래 요청 다시 시도
46-
// } catch (error) {
47-
// console.error('AT 토큰 재발급 실패:', error);
48-
// return Promise.reject(error);
49-
// }
50-
// }
51-
// return Promise.reject(error);
52-
// },
53-
// );
39+
try {
40+
await reissueToken(); // 토큰 재발급 요청
41+
return axiosInstance(originalRequest); // 원래 요청 다시 시도
42+
} catch (error) {
43+
useAuthStore.persist.clearStorage();
44+
console.error('AT 토큰 재발급 실패:', error);
45+
46+
return Promise.reject(error);
47+
}
48+
}
49+
return Promise.reject(error);
50+
},
51+
);
5452

5553
// .env에 추가하기
5654
// VITE_API_URL=http://43.203.98.65:8080

0 commit comments

Comments
 (0)