-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix : 중복 선언 제거 * env * feat : login.ts 실패 처리 삭제 * refactor : 로그인 페이지 로직 분리 / 커스텀 훅 생성 * feat : 로그아웃 함수 작성 * fix : 경로 수정 * chore : if문 제거 * feat : AuthProvider 작성 * refactor : useUserInfo 훅으로 분리 * chore : 더미데이터 바인딩 해제 * feat : 자동로그인 및 보호라우터 설정 * env * fix : return Navigate로 변경 * refactor : 중첩된 if문 제거 * Delete StoragePage.stories.tsx * Delete Storage.stories.tsx * Delete MyPage.stories.tsx * fix : 스토리북 쿼리클라이언트 설정 * fix : 쿼리클라이언트 오류 수정
- Loading branch information
Showing
8 changed files
with
149 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ReactNode, useEffect, useState } from 'react'; | ||
import { tokenStorage } from './service/auth/tokenStorage'; | ||
import { useUserInfo } from './hooks/useUserInfo'; | ||
|
||
interface AuthLayoutProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const AuthProvider = ({ children }: AuthLayoutProps) => { | ||
const [isLoading, setIsLoading] = useState(true); | ||
const { handleGetUserInfo } = useUserInfo(); | ||
|
||
useEffect(() => { | ||
const initializeAuth = async () => { | ||
const accessToken = tokenStorage.getAccessToken(); | ||
if (accessToken === null) { | ||
return; | ||
} | ||
const success = await handleGetUserInfo(); | ||
if (success) { | ||
setIsLoading(false); | ||
} | ||
}; | ||
initializeAuth(); | ||
}, []); | ||
|
||
if (isLoading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return children; | ||
}; |
Empty file.
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,28 @@ | ||
import { useToastStore } from '@/hooks/useToastStore'; | ||
import { useUserStore } from './../stores/useUserStore'; | ||
import { getUserInfo } from '@/service/user/getUserInfo'; | ||
import { logout } from './../service/auth/logout'; | ||
|
||
export const useUserInfo = () => { | ||
const { setUser } = useUserStore(); | ||
const { addToast } = useToastStore(); | ||
|
||
const handleGetUserInfo = async () => { | ||
const userInfoResponse = await getUserInfo(); | ||
console.log(userInfoResponse); | ||
if (!userInfoResponse) { | ||
addToast('유저 정보를 불러오지 못했습니다.', 'warning'); | ||
logout(); | ||
return false; | ||
} | ||
const userInfoWithEmail = { | ||
nickname: userInfoResponse.nickname || '알 수 없음', | ||
profileImageUrl: userInfoResponse.profileImageUrl || 'testimg.jpg', | ||
email: userInfoResponse.email || '알 수 없음' | ||
}; | ||
setUser(userInfoWithEmail); | ||
return true; | ||
}; | ||
|
||
return { handleGetUserInfo }; | ||
}; |
Empty file.
This file was deleted.
Oops, something went wrong.
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