UNPKG

sdk-simple-auth

Version:

Universal JavaScript/TypeScript authentication SDK with multi-backend support, automatic token refresh, and React integration

161 lines 4.19 kB
import { AuthCallbacks, AuthConfig, AuthState, AuthTokens, AuthUser, LoginCredentials, RegisterData, ExtendedSessionInfo } from '../types'; type StateChangeListener = (state: AuthState) => void; /** * Refactored AuthSDK with improved modularity and session management */ export declare class AuthSDK { private config; private state; private callbacks; private storageManager; private refreshManager; private expirationTimer; private stateChangeListeners; private isInitialized; constructor(config: AuthConfig, callbacks?: AuthCallbacks); /** * Build complete configuration with defaults */ private buildConfig; /** * Enhanced login with automatic session establishment */ login(credentials: LoginCredentials): Promise<AuthUser>; /** * Enhanced register with automatic session establishment when tokens are provided */ register(userData: RegisterData): Promise<AuthUser>; /** * Enhanced logout with complete session cleanup */ logout(): Promise<void>; /** * Enhanced token refresh with session renewal */ refreshTokens(): Promise<AuthTokens>; /** * Subscribe to authentication state changes */ onAuthStateChanged(listener: StateChangeListener): () => void; /** * Get current authentication state */ getState(): AuthState; /** * Get current authenticated user */ getCurrentUser(): AuthUser | null; /** * Get current access token */ getAccessToken(): string | null; /** * Get current refresh token */ getRefreshToken(): string | null; /** * Check if user is currently authenticated */ isAuthenticated(): Promise<boolean>; /** * Get a valid access token, refreshing if necessary */ getValidAccessToken(): Promise<string | null>; /** * Get authorization headers for API requests */ getAuthHeaders(): Promise<Record<string, string>>; /** * Debug token information */ debugToken(token?: string): void; /** * Debug API response structure */ debugResponse(response: any): void; /** * Force refresh tokens regardless of expiration */ forceRefreshTokens(): Promise<AuthTokens>; /** * Get comprehensive session information */ getExtendedSessionInfo(): Promise<ExtendedSessionInfo>; /** * Get detailed session information (legacy method) */ getSessionInfo(): Promise<{ isValid: boolean; user: AuthUser | null; tokenType: string | null; expiresIn: number | null; refreshAvailable: boolean; sessionId: string | null; }>; /** * Test extraction with mock response (debugging) */ testExtraction(response: any): void; /** * Detect token format */ private detectTokenFormat; /** * Initialize from stored authentication data */ private initializeFromStorage; /** * Establish new session with tokens and user */ private establishSession; /** * Clear current session completely */ private clearSession; /** * Handle token refresh completion */ private handleTokenRefresh; /** * Schedule automatic token expiration handling */ private scheduleTokenExpiration; /** * Handle automatic token expiration */ private handleTokenExpiration; /** * Clear expiration timer */ private clearExpirationTimer; /** * Validate token based on its type */ private isTokenValid; /** * Validate stored token using metadata */ private validateStoredToken; /** * Create default HTTP client using fetch */ private createDefaultHttpClient; /** * Set loading state */ private setLoading; /** * Set error state */ private setError; /** * Notify all state change listeners */ private notifyStateChange; /** * NUEVO: Debug current session with comprehensive info */ debugSession(): void; } export {}; //# sourceMappingURL=AuthSDK.d.ts.map