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

hotfix: 재발급시 getItem 부분 수정 #448

Merged
merged 1 commit into from
Sep 19, 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
11 changes: 5 additions & 6 deletions frontend/src/apis/getApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ const decodeToken = (token: string) => {

async function refreshToken(headers: Headers): Promise<string> {
console.log('L12 refreshTOken이 호출은 되었는지 확인', headers);
const parsedToken = JSON.parse(localStorage.getItem('userToken') as string);
console.log('getAPI Line 14', parsedToken);
const { userToken } = parsedToken;
console.log('userToken', userToken);
const accessToken = localStorage.getItem('userToken');
console.log('getAPI Line 14', accessToken);
try {
// 서버에 새로운 엑세스 토큰을 요청하기 위한 네트워크 요청을 보냅니다.
const refreshResponse = await fetch(`${DEFAULT_PROD_URL}/refresh-token`, {
method: 'POST',
headers,
body: JSON.stringify({
accessToken: userToken,
accessToken: accessToken,
}),
});

Expand All @@ -32,7 +30,7 @@ async function refreshToken(headers: Headers): Promise<string> {
}

console.log('refreshResponse', refreshResponse);

console.log('refreshResponse.text()', refreshResponse.text());
// 새로운 엑세스 토큰을 반환합니다.
return await refreshResponse.text();
} catch (error) {
Expand All @@ -59,6 +57,7 @@ async function withTokenRefresh<T>(callback: () => Promise<T>): Promise<T> {
console.log(`Authorization : Bearer ${userToken}`);
//새로운 토큰 재발급
userToken = await refreshToken(headers);
console.log('L59 userToken', userToken);
localStorage.setItem('userToken', userToken);
console.log('localStorage에 새로운 토큰 적용 성공!');
}
Expand Down
Loading