UNPKG

pagamio-frontend-commons-lib

Version:

Pagamio library for Frontend reusable components like the form engine and table container

34 lines (33 loc) 1.65 kB
interface UseSessionTimerOptions { onSessionExpired?: () => void; onSessionRefreshed?: () => void; onRefreshError?: (error: Error) => void; expiryThreshold?: number; } /** * Hook to manage session expiration and refresh logic. * Tracks the session's remaining time and provides functionality to refresh the session or handle expiration. * * @param options - Configuration options for the session timer. * @param options.onSessionExpired - Callback invoked when the session expires. * @param options.onSessionRefreshed - Callback invoked when the session is successfully refreshed. * @param options.onRefreshError - Callback invoked when an error occurs during session refresh. * @param options.expiryThreshold - Time in milliseconds before session expiry to show the modal (default: 60000ms or 60s). * * @returns An object containing: * - `showModal`: Boolean indicating whether the session expiry modal should be shown. * - `countdown`: The remaining time in seconds before session expiry. * - `loading`: Boolean indicating whether a session refresh is in progress. * - `modalDismissed`: Boolean indicating whether the modal has been dismissed. * - `handleCloseModal`: Function to close the session expiry modal. * - `handleRefreshToken`: Function to refresh the session token. */ export declare function useSessionTimer({ onSessionExpired, onSessionRefreshed, onRefreshError, expiryThreshold, }?: UseSessionTimerOptions): { showModal: boolean; countdown: number; loading: boolean; modalDismissed: boolean; handleCloseModal: () => void; handleRefreshToken: () => Promise<void>; }; export {};