-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(shelter): zustand로 authstore 생성, axiosInterceptor에 토큰 추가하는 로직 추가 * feat(shared): access token 갱신 로직 추가 * feat(shelter): accessToken hook 추가, index에 들어갔을 때 volunteers로 리다이렉트 * fix(shared): import error 해결 * fix(shared): 오타 수정 * chore(shared): react query 의존성 추가 * feat(shelter): 어플 처음 접속했을 시 로그인 상태 확인하는 기능추가 * feat(common): 로그인 했을때 유저 정보 스토어에 저장하는 로직 추가 * feat(shared): 어플 접속시 깜빡이는 현상 해결 * feat(shared): 주석 제거 및 보호소 어플일때만 리다이렉트 하도록 실행 * feat(volunteer): withLogin 컴포넌트 추가 * feat(volunteer): 권한이 있는 페이지 WithLogin으로 보호 * fix(common): 보호소 앱에 중복된 훅 제거, 봉사자 앱에 accessToken 다시 받는 mock api 추가, shard layout의 주석 제거 * rename(volunteer): withLogin 파일 이름 수정
- Loading branch information
Showing
16 changed files
with
174 additions
and
22 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
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,13 @@ | ||
import { ReactNode } from 'react'; | ||
import { Navigate } from 'react-router-dom'; | ||
import useAuthStore from 'shared/store/authStore'; | ||
|
||
export default function WithLogin({ children }: { children: ReactNode }) { | ||
const { user } = useAuthStore(); | ||
|
||
if (user) { | ||
children; | ||
} | ||
|
||
return <Navigate to="/signin" />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { SigninResponseData } from '../../types/apis/auth'; | ||
import axiosInstance from '../axiosInstance'; | ||
|
||
export const getAccessTokenAPI = () => | ||
axiosInstance.post<SigninResponseData>('/auth/refresh'); |
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,24 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { getAccessTokenAPI } from '../apis/common/AccessToken'; | ||
import useAuthStore from '../store/authStore'; | ||
|
||
export default function useAccessTokenMutation() { | ||
const { setUser } = useAuthStore(); | ||
return useMutation({ | ||
mutationFn: async () => { | ||
const { data } = await getAccessTokenAPI(); | ||
return data; | ||
}, | ||
onSuccess: ({ accessToken, userId }) => { | ||
setUser({ | ||
accessToken, | ||
userId, | ||
}); | ||
}, | ||
onError: (error) => { | ||
console.warn(error); | ||
setUser(null); | ||
}, | ||
}); | ||
} |
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,23 @@ | ||
import { create } from 'zustand'; | ||
|
||
type User = { | ||
accessToken: string; | ||
userId: number; | ||
}; | ||
|
||
interface AuthState { | ||
user: User | null; | ||
} | ||
|
||
interface AuthActions { | ||
setUser: (user: User | null) => void; | ||
} | ||
|
||
const useAuthStore = create<AuthState & AuthActions>((set) => ({ | ||
user: null, | ||
setUser: (user: User | null) => { | ||
set({ user }); | ||
}, | ||
})); | ||
|
||
export default useAuthStore; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.