fix: persistance du login admin via localStorage (zustand persist)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { apiGet } from '@/api/client';
|
||||
import { ENDPOINTS } from '@/utils/constants';
|
||||
|
||||
@@ -9,7 +10,9 @@ interface AuthStore {
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthStore>((set) => ({
|
||||
export const useAuthStore = create<AuthStore>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
apiKey: null,
|
||||
isAuthenticated: false,
|
||||
|
||||
@@ -32,4 +35,10 @@ export const useAuthStore = create<AuthStore>((set) => ({
|
||||
logout: () => {
|
||||
set({ apiKey: null, isAuthenticated: false });
|
||||
},
|
||||
}));
|
||||
}),
|
||||
{
|
||||
name: 'imago-auth',
|
||||
partialize: (state) => ({ apiKey: state.apiKey, isAuthenticated: state.isAuthenticated }),
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user