From 84b74cb3b6ce403400871879ce8e042e3e9ba835 Mon Sep 17 00:00:00 2001 From: minsu-zip Date: Sun, 11 Aug 2024 17:44:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20accessToken=20=EC=A0=84=EC=97=AD=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EA=B4=80=EB=A6=AC=20zustand=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/auth/AuthProvider.tsx | 19 +++++++++++++++++++ src/store/auth/index.ts | 2 ++ src/store/auth/useAuthStore.ts | 15 +++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/store/auth/AuthProvider.tsx create mode 100644 src/store/auth/index.ts create mode 100644 src/store/auth/useAuthStore.ts diff --git a/src/store/auth/AuthProvider.tsx b/src/store/auth/AuthProvider.tsx new file mode 100644 index 0000000..4f6030f --- /dev/null +++ b/src/store/auth/AuthProvider.tsx @@ -0,0 +1,19 @@ +"use client" + +import useAuthStore from "./useAuthStore" + +interface AuthContextProps { + accessToken: string | null +} + +const AuthProvider = ({ accessToken }: AuthContextProps) => { + const setAccessToken = useAuthStore((state) => state.setAccessToken) + + if (accessToken) { + setAccessToken(accessToken) + } + + return null +} + +export default AuthProvider diff --git a/src/store/auth/index.ts b/src/store/auth/index.ts new file mode 100644 index 0000000..f7b6780 --- /dev/null +++ b/src/store/auth/index.ts @@ -0,0 +1,2 @@ +export { default as AuthProvider } from "./AuthProvider" +export { default as useAuthStore } from "./useAuthStore" diff --git a/src/store/auth/useAuthStore.ts b/src/store/auth/useAuthStore.ts new file mode 100644 index 0000000..3540729 --- /dev/null +++ b/src/store/auth/useAuthStore.ts @@ -0,0 +1,15 @@ +import { create } from "zustand" + +interface AuthState { + accessToken: string | null + setAccessToken: (token: string | null) => void + clearAuth: () => void +} + +const useAuthStore = create((set) => ({ + accessToken: null, + setAccessToken: (token) => set({ accessToken: token }), + clearAuth: () => set({ accessToken: null }), +})) + +export default useAuthStore