Skip to content

Commit

Permalink
console ์ฒดํฌ (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
semnil5202 authored Sep 20, 2023
1 parent 9434c4a commit 3d1fa9c
Showing 1 changed file with 11 additions and 12 deletions.
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

0 comments on commit 3d1fa9c

Please sign in to comment.