-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/ user store - zustand 기반 전역 유저 상태 관리 #82
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
Merged
Merged
Conversation
This file contains hidden or 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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
summerDev96
approved these changes
Jul 29, 2025
Comment on lines
+6
to
+23
| * 앱 진입 시 유저 정보를 패치하고 Zustand에 저장하는 훅 */ | ||
| export const useInitUser = () => { | ||
| const setUser = useUserStore((state) => state.setUser); | ||
|
|
||
| /* 처음에만 실행 */ | ||
| useEffect(() => { | ||
| const fetchUser = async () => { | ||
| try { | ||
| const user = await getUser(); | ||
| setUser(user); | ||
| } catch (error) { | ||
| // 로그인 안 돼있는 경우 무시 | ||
| } | ||
| }; | ||
|
|
||
| fetchUser(); | ||
| }, [setUser]); | ||
| }; |
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
머지 후 로그인 시 추가하도록 하겠습니다!
626-ju
approved these changes
Jul 29, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📦 Pull Request
📝 요약(Summary)
Zustand기반의 전역 유저 상태 스토어useUserStore를 생성했습니다.클라이언트 렌더링(CSR) 환경에서 앱 진입 시 유저 정보를 패치해 상태를 초기화하는
useInitUser훅을 작성했습니다.useUserStore()직접 호출 대신,useUser()훅을 통해 상태를 접근·관리하는 방식으로 통일되어 있습니다.현재는 CSR 방식만 대응 중이며, SSR이 필요한 경우 getServerSideProps에서 유저 데이터를 받아 페이지 props로 전달하고, 클라이언트에서 setUser()로 상태에 반영하는 방식으로 확장할 수 있습니다.
💬 공유사항 to 리뷰어
setUser()를 호출해 상태에 저장해야 합니다. (자세한 내용은 하단 참고)🗂️ 관련 이슈
#83
📸 스크린샷
✅ 체크리스트
useInitUser) 작성setUser,clearUser) 구현해야 할 작업
1. 로그인 성공 시
/users/meAPI를 호출해 유저 정보를 받아옵니다.setUser()로 상태에 저장합니다.2. 로그아웃 시
clearUser()를 호출해 상태를 초기화합니다.예시 코드
로그인 처리
로그아웃 처리
Zustand 스토어 구조 예시 (참고용)
정리
/users/me로 유저 정보를 받아와 상태에 저장해 주세요.clearUser()도 호출해야 합니다.