analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
45 lines • 1.34 kB
JavaScript
// src/components/Auth/zustandAuthAdapter.ts
function createZustandAuthAdapter(useAuthStore) {
return {
/**
* Check if the user is authenticated based on sessionInfo and tokens
*
* @returns {Promise<boolean>} Promise that resolves to authentication status
*/
checkAuth: async () => {
const { sessionInfo, tokens } = useAuthStore.getState();
return Boolean(sessionInfo && tokens);
},
/**
* Get the current user from the store
*
* @returns {unknown} Current user data from the store
*/
getUser: () => useAuthStore.getState().user,
/**
* Get the current session information from the store
*
* @returns {unknown} Current session info from the store
*/
getSessionInfo: () => useAuthStore.getState().sessionInfo,
/**
* Get the current authentication tokens from the store
*
* @returns {unknown} Current tokens from the store
*/
getTokens: () => useAuthStore.getState().tokens,
/**
* Sign out the user by calling the store's signOut function if available
*
* @returns {void}
*/
signOut: () => {
const signOutFn = useAuthStore.getState().signOut;
if (typeof signOutFn === "function") signOutFn();
}
};
}
export {
createZustandAuthAdapter
};
//# sourceMappingURL=index.mjs.map