analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
68 lines • 3.15 kB
TypeScript
/**
* Options interface for the useUrlAuthentication hook
*
* @template Tokens - Type for authentication tokens
* @template Session - Type for session information
* @template Profile - Type for profile information
* @template User - Type for user information
*
* @interface UseUrlAuthOptions
* @property {(tokens: Tokens) => void} setTokens - Function to set authentication tokens
* @property {(session: Session) => void} setSessionInfo - Function to set session information
* @property {(profile: Profile) => void} [setSelectedProfile] - Optional function to set selected profile
* @property {(user: User) => void} [setUser] - Optional function to set user data
* @property {object} api - API instance with get method
* @property {(endpoint: string, config: unknown) => Promise<unknown>} api.get - API get method
* @property {string} endpoint - API endpoint to fetch session data
* @property {(searchParams: URLSearchParams) => object} [extractParams] - Custom parameter extraction function
* @property {() => void} [clearParamsFromURL] - Function to clear URL parameters after processing
* @property {number} [maxRetries] - Maximum number of retry attempts (default: 3)
* @property {number} [retryDelay] - Base delay between retries in milliseconds (default: 1000)
* @property {(error: unknown) => void} [onError] - Error handler callback
*/
export interface UseUrlAuthOptions<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown> {
setTokens: (tokens: Tokens) => void;
setSessionInfo: (session: Session) => void;
setSelectedProfile?: (profile: Profile) => void;
setUser?: (user: User) => void;
api: {
get: (endpoint: string, config: unknown) => Promise<unknown>;
};
endpoint: string;
extractParams?: (searchParams: URLSearchParams) => {
sessionId: string;
token: string;
refreshToken: string;
};
clearParamsFromURL?: () => void;
maxRetries?: number;
retryDelay?: number;
onError?: (error: unknown) => void;
}
/**
* Hook for handling URL-based authentication
* Extracts authentication parameters from URL and processes them
*
* @template Tokens - Type for authentication tokens
* @template Session - Type for session information
* @template Profile - Type for profile information
* @template User - Type for user information
*
* @param {UseUrlAuthOptions<Tokens, Session, Profile, User>} options - Configuration options
* @returns {void}
*
* @example
* ```typescript
* useUrlAuthentication({
* setTokens: (tokens) => authStore.setTokens(tokens),
* setSessionInfo: (session) => authStore.setSessionInfo(session),
* setSelectedProfile: (profile) => authStore.setProfile(profile),
* setUser: (user) => authStore.setUser(user),
* api: apiInstance,
* endpoint: '/auth/session',
* clearParamsFromURL: () => navigate('/', { replace: true })
* });
* ```
*/
export declare function useUrlAuthentication<Tokens = unknown, Session = unknown, Profile = unknown, User = unknown>(options: UseUrlAuthOptions<Tokens, Session, Profile, User>): void;
//# sourceMappingURL=useUrlAuthentication.d.ts.map