Skip to content

Commit

Permalink
Merge pull request #129 from YAPP-Github/feature/FE-088
Browse files Browse the repository at this point in the history
feature/FE-088 : 로그인 유지 로직 추가
  • Loading branch information
naro-Kim authored Aug 1, 2023
2 parents af22cc4 + cdac5ea commit 2851f7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/api/user/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class UserAPI {
async postLogout() {
return request.post('v1/users/logout').json();
}
async postRefresh() {
return request.post('v1/users/refresh').json();
}
}

export const userAPI = new UserAPI();
22 changes: 12 additions & 10 deletions src/utils/ky/hooks/processResponse.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { AfterResponseHook } from 'ky';
import ky, { AfterResponseHook } from 'ky';
import { ResponseData } from '@/types/data';

import { userAPI } from '@/api/user/api';
/** response 에서 필요한 데이터 추출 및 에러 전처리 */
const processResponse: AfterResponseHook = async (request, options, response) => {
if (response.status === 204) {
return new Response(undefined, { status: 204 });
}

const data: ResponseData = await response?.json();
return new Response(JSON.stringify(data?.result ?? data?.message), {
status: response.status,
});
if (response.status === 204) {
return new Response(undefined, { status: 204 });
} else if (response.status === 498) {
await userAPI.postRefresh();
return ky(request);
}
const data: ResponseData = await response?.json();
return new Response(JSON.stringify(data?.result ?? data?.message), {
status: response.status,
});
};

export { processResponse };

0 comments on commit 2851f7e

Please sign in to comment.