- useAuthStore: 인증 상태 관리 (localStorage persist) - useScheduleStore: 스케줄 페이지 상태 (검색, 필터, 날짜, 뷰) - useUIStore: UI 상태 (토스트, 모달, 라이트박스, 확인 다이얼로그) - stores/index.js: 통합 export Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
1 KiB
JavaScript
54 lines
1 KiB
JavaScript
import { create } from 'zustand';
|
|
import { persist } from 'zustand/middleware';
|
|
|
|
/**
|
|
* 인증 상태 스토어
|
|
* localStorage에 지속되어 새로고침 후에도 유지
|
|
*/
|
|
const useAuthStore = create(
|
|
persist(
|
|
(set, get) => ({
|
|
// 상태
|
|
token: null,
|
|
user: null,
|
|
isAuthenticated: false,
|
|
|
|
// 로그인
|
|
login: (token, user) => {
|
|
set({
|
|
token,
|
|
user,
|
|
isAuthenticated: true,
|
|
});
|
|
},
|
|
|
|
// 로그아웃
|
|
logout: () => {
|
|
set({
|
|
token: null,
|
|
user: null,
|
|
isAuthenticated: false,
|
|
});
|
|
},
|
|
|
|
// 토큰 가져오기
|
|
getToken: () => get().token,
|
|
|
|
// 인증 여부 확인
|
|
checkAuth: () => {
|
|
const { token } = get();
|
|
return !!token;
|
|
},
|
|
}),
|
|
{
|
|
name: 'auth-storage',
|
|
partialize: (state) => ({
|
|
token: state.token,
|
|
user: state.user,
|
|
isAuthenticated: state.isAuthenticated,
|
|
}),
|
|
}
|
|
)
|
|
);
|
|
|
|
export default useAuthStore;
|