update: Set zustand storage.

mack-mac
mackt 8 months ago
parent 6d7172515e
commit a3def0adc4

@ -1,6 +1,7 @@
import { produce } from 'immer';
import { setCookie } from 'nookies';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { apiGetMyUserInfo, apiUserLogin } from '@/services';
@ -19,8 +20,10 @@ interface UserState {
getUserInfo: () => Promise<boolean>;
}
// 创建状态存储
const useUserStore = create<UserState>((set) => {
const useUserStore = create<UserState>()(
devtools(
persist(
(set) => {
const getUserInfo = async () => {
const result = await apiGetMyUserInfo();
if (result.code === 200) await set(produce((state) => void (state.userInfo = result.data)));
@ -67,6 +70,13 @@ const useUserStore = create<UserState>((set) => {
return await getUserInfo();
},
};
});
},
{
name: 'user',
getStorage: () => localStorage,
},
),
),
);
export default useUserStore;

Loading…
Cancel
Save