-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 로그인, refresh api 추가 * feat: jwt 유효 기간을 확인하고 refresh 후 api 요청 * fix: 누락된 return문 추가 * refactor: useLogin 수정 * refactor: useFetch 제거 * feat: jwt 유효시간 확인 유틸 추가 * feat: auth 관련 api 분리 * feat: 토큰 제거시 쿼리무효화 * feat: default retry 1 설정 * refactor: useLogin 제거 * feat: 로그인 에러 발생 이후 removeQuery * feat: 로컬 로그인 기능 추가 * feat: 로그인 api then/catch 적용 * Merge branch 'dev/FE' into feat/614 * fix: mockData 중복 태그 제거 * feat: 인증 관련 오류 발생시 로그아웃 * feat: 로그아웃 api 추가 * fix: 로그아웃 api PATCH로 변경 * fix: 로그아웃 msw 수정
- Loading branch information
Showing
34 changed files
with
325 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { ACCESS_TOKEN_LOCAL_STORAGE_KEY, BATON_BASE_URL } from '@/constants'; | ||
import { queryClient } from '@/hooks/query/queryClient'; | ||
import { getRestMinute } from '@/utils/jwt'; | ||
|
||
export const getAccessToken = () => localStorage.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY); | ||
|
||
const removeAccessToken = () => { | ||
localStorage.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY); | ||
}; | ||
|
||
export const isLogin = () => Boolean(getAccessToken()); | ||
|
||
export const logout = () => { | ||
patchRefreshToken(); | ||
|
||
removeAccessToken(); | ||
|
||
queryClient.removeQueries({ queryKey: ['headerProfile'] }); | ||
}; | ||
|
||
const saveAccessToken = (response: Response) => { | ||
if (!response.ok) { | ||
removeAccessToken(); | ||
queryClient.resetQueries({ queryKey: ['headerProfile'] }); | ||
|
||
return; | ||
} | ||
|
||
const jwt = response.headers.get('Authorization'); | ||
|
||
if (jwt) { | ||
localStorage.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, jwt); | ||
queryClient.resetQueries({ queryKey: ['headerProfile'] }); | ||
} | ||
}; | ||
|
||
export const issueLoginToken = async (authCode: string) => { | ||
const response = await fetch(`${BATON_BASE_URL}/oauth/login/github?code=${authCode}`, { | ||
method: 'GET', | ||
headers: { | ||
credentials: 'include', | ||
}, | ||
}); | ||
|
||
saveAccessToken(response); | ||
|
||
return response; | ||
}; | ||
|
||
export const postRefreshToken = async () => { | ||
const response = await fetch(`${BATON_BASE_URL}/oauth/refresh`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
credentials: 'include', | ||
}, | ||
}); | ||
|
||
saveAccessToken(response); | ||
|
||
return response; | ||
}; | ||
|
||
export const patchRefreshToken = async () => { | ||
const response = await fetch(`${BATON_BASE_URL}/oauth/logout`, { | ||
method: 'PATCH', | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
}, | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
export const checkLoginToken = async () => { | ||
const jwt = getAccessToken(); | ||
|
||
if (!jwt || getRestMinute(jwt) > 2) return; | ||
|
||
return await postRefreshToken(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
frontend/src/components/SupporterCard/SupporterCartList/SupporterCardList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.