@srirag/leaf-global-store
v2.0.0
Published
Shared Zustand store for auth session state (tokens and user details). State is persisted to `localStorage` under the key `global-store`.
Downloads
147
Readme
@srirag/leaf-global-store
Shared Zustand store for auth session state (tokens and user details). State is persisted to localStorage under the key global-store.
Install
npm install @srirag/leaf-global-storeAPI
State
userDetails— user object ornullaccessToken— string ornullrefreshToken— string ornull
Actions
setUserDetails(userDetails)setAccessToken(accessToken)setRefreshToken(refreshToken)removeCredentials()— clears all of the above
Usage
import useGlobalStore from '@srirag/leaf-global-store';
// In a React component
const { accessToken, setAccessToken, removeCredentials } = useGlobalStore();
// Outside React (e.g. after login in a remote MF)
useGlobalStore.getState().setAccessToken(token);
useGlobalStore.getState().setUserDetails({ /* ... */ });
useGlobalStore.getState().removeCredentials();Microfrontend note
The host app re-exports this package as hostApp/GlobalStore via Module Federation. Remotes can use import('hostApp/GlobalStore') or depend on @srirag/leaf-global-store directly.
Note
Built with Zustand persist middleware. zustand is included as a dependency of this package.
