Skip to content

Commit

Permalink
feat: accessToken 전역 상태관리 zustand정의
Browse files Browse the repository at this point in the history
  • Loading branch information
minsu-zip committed Aug 11, 2024
1 parent b7cb075 commit 84b74cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/store/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/store/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as AuthProvider } from "./AuthProvider"
export { default as useAuthStore } from "./useAuthStore"
15 changes: 15 additions & 0 deletions src/store/auth/useAuthStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { create } from "zustand"

interface AuthState {
accessToken: string | null
setAccessToken: (token: string | null) => void
clearAuth: () => void
}

const useAuthStore = create<AuthState>((set) => ({
accessToken: null,
setAccessToken: (token) => set({ accessToken: token }),
clearAuth: () => set({ accessToken: null }),
}))

export default useAuthStore

0 comments on commit 84b74cb

Please sign in to comment.