Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refresh response console 체크 #457

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions frontend/src/apis/getApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ async function refreshToken(headers: Headers): Promise<Response> {
return refreshResponse;
}

console.log('refreshResponse:', refreshResponse);

const accessToken = localStorage.getItem('userToken');
try {
// 서버에 새로운 엑세스 토큰을 요청하기 위한 네트워크 요청을 보냅니다.
Expand All @@ -27,11 +29,17 @@ async function refreshToken(headers: Headers): Promise<Response> {
}),
});

const promiseResponse = refreshResponse;
const responseData = await refreshResponse;
refreshResponse = null;

// 서버 응답이 성공적인지 확인합니다.
if (!responseData.ok) {
console.log('refreshResponse.ok하지 못함');
throw new Error('Failed to refresh access token.');
}

// 새로운 엑세스 토큰을 반환합니다.
return promiseResponse;
return responseData;
} catch (error) {
// 네트워크 요청 실패 또는 예외 발생 시 예외를 캐치하여 처리합니다.
console.error('네트워크 요청 실패 또는 예외 발생:', error);
Expand All @@ -46,18 +54,9 @@ const isTokenExpired = (token: string) => {

async function updateToken(headers: Headers) {
const response = await refreshToken(headers);

console.log('50, response : ', response);

// 서버 응답이 성공적인지 확인합니다.
if (!response.ok) {
console.log('refreshResponse.ok하지 못함');
throw new Error('Failed to refresh access token.');
}

const newToken = await response.json();

console.log(newToken);
console.log('newToken:', newToken);

localStorage.setItem('userToken', newToken.accessToken);
}
Expand Down