UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

76 lines (74 loc) 2.12 kB
/** * Generic adapter for integrating AuthProvider with Zustand stores * Users should import this file and pass their store instance * * @template S - Zustand store type that contains auth-related state * @param {object} useAuthStore - Zustand store hook with getState method * @param {() => S} useAuthStore.getState - Function to get current store state * @returns {object} Adapter object with auth functions * * @example * ```typescript * // Define your Zustand store type * interface AuthStore { * sessionInfo?: SessionInfo; * tokens?: AuthTokens; * user?: AuthUser; * signOut: () => void; * } * * // Create the adapter * const authAdapter = createZustandAuthAdapter(useAuthStore); * * // Use with AuthProvider * <AuthProvider * checkAuthFn={authAdapter.checkAuth} * signOutFn={authAdapter.signOut} * getUserFn={authAdapter.getUser} * getSessionFn={authAdapter.getSessionInfo} * getTokensFn={authAdapter.getTokens} * > * <App /> * </AuthProvider> * ``` */ declare function createZustandAuthAdapter<S extends { sessionInfo?: unknown; tokens?: unknown; user?: unknown; signOut?: () => void; }>(useAuthStore: { getState: () => S; }): { /** * Check if the user is authenticated based on sessionInfo and tokens * * @returns {Promise<boolean>} Promise that resolves to authentication status */ checkAuth: () => Promise<boolean>; /** * Get the current user from the store * * @returns {unknown} Current user data from the store */ getUser: () => unknown; /** * Get the current session information from the store * * @returns {unknown} Current session info from the store */ getSessionInfo: () => unknown; /** * Get the current authentication tokens from the store * * @returns {unknown} Current tokens from the store */ getTokens: () => unknown; /** * Sign out the user by calling the store's signOut function if available * * @returns {void} */ signOut: () => void; }; export { createZustandAuthAdapter };