-
Notifications
You must be signed in to change notification settings - Fork 2
[Feat] 로그인 상태 관리 #191
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
[Feat] 로그인 상태 관리 #191
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bb5777f
chore: zustand 라이브러리 추가
kwonsaebom 467589a
feat: 유저 & 함수 타입 지정
kwonsaebom 3969e9f
feat: zuestand 기반 useAuthStore 구현
kwonsaebom 5a640d9
chore: 함수 이름 통일
kwonsaebom 02c7186
refactor: 중복된 타입 파일 제거
kwonsaebom d9af138
feat: useAuthStore 훅 적용
kwonsaebom 45593c1
fix: 에러 수정
kwonsaebom 4c11908
feat: userModal 컴포넌트에 user 상태 적용
kwonsaebom 769697e
feat: 상태 관리에 isLoggedIn 추가
kwonsaebom 1575b23
feat: 테스트 코드
kwonsaebom 5e1ec24
refactor: user의 기본 값 변경
kwonsaebom 14d8eb4
feat: 분기 처리 조건 수정
kwonsaebom 1e48f00
refactor: 유저 데이터가 존재할 때만 로컬 스토리지에 저장하도록 수정
kwonsaebom bda0d57
fix: 린트 에러 해결
kwonsaebom 94f1d18
refactor: 객체 형식으로 상태 useAuthStore 호출
kwonsaebom 839e240
refactor: button으로 img 감싸서 접근성 높이기
kwonsaebom 27f87b6
refactor: 토큰을 기준으로 로그인 기준 처리
kwonsaebom 1def14c
fix: 주석 제거
kwonsaebom 8a711b3
feat: 목표 작성 상태에 따른 분기 처리
kwonsaebom 193ddb4
feat: 리프레시 토큰 발급 추가 & axiosInstance 응답 변경
kwonsaebom 44b39f3
fix: 충돌 해결
kwonsaebom 2e641c6
Merge branch 'develop' into feat/#187/loginState
kwonsaebom 38d38a8
fix: 리뷰 수정
kwonsaebom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| export interface AnswerType { | ||
| questionId: number; | ||
| choiceId: number; | ||
| } | ||
|
|
||
| export interface UserType { | ||
| id?: number; | ||
| name: string; | ||
| email: string; | ||
| birthday?: string; | ||
| job?: string; | ||
| profileImageUrl: string; | ||
| answers?: AnswerType[]; | ||
| } | ||
|
|
||
| export interface AuthStoreType { | ||
| user: UserType; | ||
| isLoggedIn: boolean; | ||
| setUser: (newUser: UserType) => void; | ||
| resetUser: () => void; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { create } from 'zustand'; | ||
| import { createJSONStorage, persist } from 'zustand/middleware'; | ||
|
|
||
| import type { AuthStoreType, UserType } from '@/store/types/authTypes'; | ||
|
|
||
| const defaultUser: UserType = { | ||
| name: '', | ||
| email: '', | ||
| profileImageUrl: '', | ||
| }; | ||
| const token = localStorage.getItem('accessToken'); | ||
|
|
||
| export const useAuthStore = create<AuthStoreType>()( | ||
| persist( | ||
| (set) => ({ | ||
| user: defaultUser, | ||
| isLoggedIn: !!token, | ||
kwonsaebom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setUser: (newUser) => set({ user: newUser, isLoggedIn: true }), | ||
| resetUser: () => set({ user: defaultUser, isLoggedIn: false }), | ||
| }), | ||
| { | ||
| name: 'auth-storage', | ||
| storage: createJSONStorage(() => ({ | ||
| getItem: (name) => localStorage.getItem(name), | ||
| setItem: (name, value) => { | ||
| const { state } = JSON.parse(value) as { state: AuthStoreType }; | ||
| if (!state.isLoggedIn) { | ||
| localStorage.removeItem(name); | ||
| return; | ||
| } | ||
| localStorage.setItem(name, value); | ||
| }, | ||
| removeItem: (name) => localStorage.removeItem(name), | ||
| })), | ||
| }, | ||
| ), | ||
| ); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.