From b114256f9e19382b82c4f962495558a734ac6fe8 Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Tue, 29 Jul 2025 19:00:56 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20zustand=20userStore=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/userStore.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/stores/userStore.ts diff --git a/src/stores/userStore.ts b/src/stores/userStore.ts new file mode 100644 index 0000000..3644a57 --- /dev/null +++ b/src/stores/userStore.ts @@ -0,0 +1,32 @@ +import { create } from 'zustand'; + +/* 유저 정보 타입 */ +interface User { + id: number; + nickname: string; + image: string | null; + teamId: string; + createdAt: string; + updatedAt: string; +} + +/* Zustand 유저 상태 저장소 타입 */ +interface UserStore { + user: User | null; + isLoggedIn: boolean; + + /* 유저 정보 설정 (로그인 등) */ + setUser: (user: User) => void; + + /* 유저 정보 초기화 (로그아웃 등) */ + clearUser: () => void; +} + +/** + * 유저 상태 전역 스토어 */ +export const useUserStore = create((set) => ({ + user: null, + isLoggedIn: false, + setUser: (user) => set({ user, isLoggedIn: true }), + clearUser: () => set({ user: null, isLoggedIn: false }), +})); From 4909fb018d4a7b3801280eff453447404bf3ecdc Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Tue, 29 Jul 2025 19:02:14 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=EC=B2=98=EC=9D=8C=20=EC=A7=84?= =?UTF-8?q?=EC=9E=85=20=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=8F=BC?= =?UTF-8?q?=EC=9E=88=EC=9C=BC=EB=A9=B4=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20hook=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=5Fapp.tsx=EC=97=90=20?= =?UTF-8?q?=EB=B0=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useInitUser.tsx | 23 +++++++++++++++++++++++ src/pages/_app.tsx | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 src/hooks/useInitUser.tsx diff --git a/src/hooks/useInitUser.tsx b/src/hooks/useInitUser.tsx new file mode 100644 index 0000000..a045757 --- /dev/null +++ b/src/hooks/useInitUser.tsx @@ -0,0 +1,23 @@ +import { useEffect } from 'react'; +import { getUser } from '@/api/user'; +import { useUserStore } from '@/stores/userStore'; + +/** + * 앱 진입 시 유저 정보를 패치하고 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]); +}; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 3ce5fbd..0b7cffc 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -8,10 +8,12 @@ import { useRouter } from 'next/router'; import Gnb from '@/components/common/Gnb'; import type { AppProps } from 'next/app'; +import { useInitUser } from '@/hooks/useInitUser'; const queryClient = new QueryClient(); export default function App({ Component, pageProps }: AppProps) { + useInitUser(); const { pathname } = useRouter(); const pagesWithoutGnb = ['/signup', '/signin', '/oauth/kakao', '/oauth/signup/kakao', '/_error']; const hideHeader = pagesWithoutGnb.includes(pathname); From 7285d8aece250a8e25d2c3e63a478e26606e09ca Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Tue, 29 Jul 2025 19:03:31 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=EC=A0=84=EC=97=AD=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=83=81=ED=83=9C=EC=97=90=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8A=94=20=EC=BB=A4=EC=8A=A4?= =?UTF-8?q?=ED=85=80=20hook=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useUser.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/hooks/useUser.tsx diff --git a/src/hooks/useUser.tsx b/src/hooks/useUser.tsx new file mode 100644 index 0000000..118a368 --- /dev/null +++ b/src/hooks/useUser.tsx @@ -0,0 +1,12 @@ +import { useUserStore } from '@/stores/userStore'; + +/** + * 전역 유저 상태를 쉽게 접근할 수 있는 커스텀 훅 */ +export const useUser = () => { + const user = useUserStore((state) => state.user); + const isLoggedIn = useUserStore((state) => state.isLoggedIn); + const setUser = useUserStore((state) => state.setUser); + const clearUser = useUserStore((state) => state.clearUser); + + return { user, isLoggedIn, setUser, clearUser }; +}; From 349aff211524e4bff07405cf012550ebc1698d0a Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 00:47:10 +0900 Subject: [PATCH 4/9] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94=20icon?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/Star.svg | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/assets/icons/Star.svg diff --git a/src/assets/icons/Star.svg b/src/assets/icons/Star.svg deleted file mode 100644 index a109d75..0000000 --- a/src/assets/icons/Star.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From 5800fd1de52c03def3362171181ae131764c3ced Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 00:58:37 +0900 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20star.svg=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(=EC=83=88=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B3=BC=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/star.svg | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/assets/icons/star.svg diff --git a/src/assets/icons/star.svg b/src/assets/icons/star.svg deleted file mode 100644 index 81950d8..0000000 --- a/src/assets/icons/star.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From 45efac1322520a4f6013b3505a89f33d297eedbd Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 00:59:01 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix:=20star.svg=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(=EC=83=88=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/star.svg | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/assets/icons/star.svg diff --git a/src/assets/icons/star.svg b/src/assets/icons/star.svg new file mode 100644 index 0000000..81950d8 --- /dev/null +++ b/src/assets/icons/star.svg @@ -0,0 +1,3 @@ + + + From eb478ea9bcbcdd8042ca0c6d09cf746757281b07 Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 01:06:07 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20star.svg=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(=EC=83=88=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B3=BC=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/star.svg | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/assets/icons/star.svg diff --git a/src/assets/icons/star.svg b/src/assets/icons/star.svg deleted file mode 100644 index 81950d8..0000000 --- a/src/assets/icons/star.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From 4bf114af66b4688abe8cdbe8eae2d0618a6cf4cf Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 01:06:47 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20star.svg=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(=EC=83=88=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B3=BC=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/icons/star.svg | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/assets/icons/star.svg diff --git a/src/assets/icons/star.svg b/src/assets/icons/star.svg new file mode 100644 index 0000000..81950d8 --- /dev/null +++ b/src/assets/icons/star.svg @@ -0,0 +1,3 @@ + + + From d1ab3d5c653f7e925dbaf29cd3f2c6dab60dcdfd Mon Sep 17 00:00:00 2001 From: youjin-hub Date: Wed, 30 Jul 2025 01:11:26 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20star.svg=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC(svg=20=EC=BA=90=EC=8B=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 305b60c..af73917 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ "@typescript-eslint/parser": "^6.21.0", "autoprefixer": "^10", "eslint": "^8.57.1", - "eslint-config-next": "^13.5.11", + "eslint-config-next": "13.5.11", "eslint-config-prettier": "^10.1.5", "eslint-plugin-import": "^2.32.0", "eslint-plugin-prettier": "^5.5.1", @@ -53,7 +53,7 @@ "eslint-plugin-react-hooks": "^5.2.0", "husky": "^9.1.7", "lint-staged": "^16.1.2", - "next": "^13.5.11", + "next": "13.5.11", "tailwindcss": "^3.4.4", "typescript": "~5.3.0" }