75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
"use client";
|
|
|
|
import { create } from "zustand";
|
|
import { persist } from "zustand/middleware";
|
|
import { createStore } from "zustand/vanilla";
|
|
|
|
export interface IUserInfo {
|
|
regDt: string;
|
|
mdfcnDt: string;
|
|
rgtr: string;
|
|
mdfr: string;
|
|
adminRoleYn: string;
|
|
userUnqId: string;
|
|
userId: string;
|
|
userName: string;
|
|
email: string;
|
|
encryptedPassword: string;
|
|
refreshToken: string;
|
|
userStateCode: string;
|
|
lastLoginDate: string;
|
|
loginFailCount: number;
|
|
pswdHnt: string;
|
|
pswdAns: string;
|
|
mphn: string;
|
|
telno: string;
|
|
zip: string;
|
|
addr: string;
|
|
daddr: string;
|
|
laeSeCd: string;
|
|
ogdpSeCd: string;
|
|
aprvYn: string;
|
|
autzrId: string;
|
|
expryYmd: string;
|
|
lastPswdChgDt: string;
|
|
googleId: string;
|
|
kakaoId: string;
|
|
naverId: string;
|
|
isSocialUser: boolean;
|
|
hasPassword: boolean;
|
|
}
|
|
|
|
export type UserState = {
|
|
userInfo: IUserInfo | null;
|
|
};
|
|
|
|
type UserStore = {
|
|
userInfo: IUserInfo | null;
|
|
setUserInfo: (userInfo: IUserInfo | null) => void;
|
|
};
|
|
|
|
// ✅ zustand 기본 create + persist 적용
|
|
export const useUserStore = create<UserStore>()(
|
|
persist(
|
|
(set) => ({
|
|
userInfo: null,
|
|
setUserInfo: (userInfo) => set({ userInfo }),
|
|
}),
|
|
{
|
|
name: "user-store", // localStorage 키
|
|
partialize: (state) => ({ userInfo: state.userInfo }), // 선택적 저장
|
|
},
|
|
),
|
|
);
|
|
|
|
export const defaultInitState: UserState = {
|
|
userInfo: null,
|
|
};
|
|
|
|
export const createUserStore = (initState: UserState = defaultInitState) => {
|
|
return createStore<UserStore>()((set) => ({
|
|
...initState,
|
|
setUserInfo: (userInfo: IUserInfo | null) => set(() => ({ userInfo })),
|
|
}));
|
|
};
|