UNPKG

@gsarthak783/accesskit-auth

Version:

JavaScript/TypeScript SDK for AccessKit Authentication System - Easy auth integration for any project

130 lines 3.85 kB
import { AuthConfig, TokenStorage, User, CreateUserData, LoginCredentials, UpdateUserData, AuthResponse, ApiResponse, AuthEvent, AuthEventData, PaginationOptions, PaginatedResponse, ExportOptions, ImportOptions, ExportData, ChangePasswordData, UpdateEmailData, ReauthenticateData } from './types'; type EventListener = (data: AuthEventData) => void; export declare class AuthClient { private config; private http; private storage; private eventListeners; private refreshPromise; private currentUser; private initialized; private initPromise; constructor(config: AuthConfig, storage?: TokenStorage); /** * Initialize auth state by checking stored tokens */ private initialize; /** * Get the current authenticated user (from memory, no API call) */ getCurrentUser(): User | null; /** * Check if user is authenticated (has valid tokens) */ isAuthenticated(): boolean; /** * Subscribe to auth state changes * Returns an unsubscribe function */ onAuthStateChange(callback: (user: User | null, isAuthenticated: boolean) => void): () => void; /** * Create axios instance with default configuration */ private createHttpClient; /** * Setup request/response interceptors for automatic token handling */ private setupInterceptors; /** * Event system for auth state changes */ on(event: AuthEvent, listener: EventListener): void; off(event: AuthEvent, listener: EventListener): void; private emit; /** * Register a new user */ register(userData: CreateUserData): Promise<AuthResponse>; /** * Login user */ login(credentials: LoginCredentials): Promise<AuthResponse>; /** * Logout user */ logout(): Promise<void>; /** * Get current user profile */ getProfile(): Promise<User>; /** * Update user profile */ updateProfile(data: UpdateUserData): Promise<User>; /** * Refresh access token */ refreshToken(): Promise<string>; private performTokenRefresh; /** * Request password reset */ requestPasswordReset(email: string): Promise<void>; /** * Reset password with token */ resetPassword(token: string, password: string): Promise<void>; /** * Verify email address */ verifyEmail(token: string): Promise<void>; /** * Update user password */ updatePassword(data: ChangePasswordData): Promise<void>; /** * Update user email */ updateEmail(data: UpdateEmailData): Promise<{ email: string; isVerified: boolean; }>; /** * Reauthenticate user with credentials * This is useful for sensitive operations that require password confirmation */ reauthenticateWithCredential(data: ReauthenticateData): Promise<{ authenticated: boolean; authenticatedAt: string; }>; /** * Get current access token */ getAccessToken(): string | null; /** * Export user data (requires admin access) */ exportUsers(options?: ExportOptions): Promise<ExportData>; /** * Import user data (requires admin access) */ importUsers(data: ExportData, options?: ImportOptions): Promise<ApiResponse>; /** * Get all users (admin only, with pagination) */ getUsers(options?: PaginationOptions): Promise<PaginatedResponse<User>>; /** * Delete a user (admin only) */ deleteUser(userId: string): Promise<void>; /** * Update user status (admin only) */ updateUserStatus(userId: string, isActive: boolean): Promise<User>; /** * Get user by ID (admin only) */ getUser(userId: string): Promise<User>; } export {}; //# sourceMappingURL=auth-client.d.ts.map