import { BaseRouteGuard, GuardContext, GuardResultObject } from './route-guard'; /** * Authentication guard configuration */ export interface AuthGuardConfig { /** Guard name */ readonly name?: string; /** Path to redirect unauthenticated users */ readonly loginPath?: string; /** Query parameter name for return URL */ readonly returnUrlParam?: string; /** Check if user is authenticated */ readonly isAuthenticated?: (context: GuardContext) => boolean | Promise; /** Custom authentication check with full context */ readonly checkAuth?: (context: GuardContext) => GuardResultObject | Promise; /** Public paths that don't require authentication */ readonly publicPaths?: readonly string[]; /** Path patterns that require authentication */ readonly protectedPaths?: readonly string[]; /** Whether to preserve query params in return URL */ readonly preserveQuery?: boolean; /** Custom redirect builder */ readonly buildRedirect?: (context: GuardContext) => string; /** Session validation function */ readonly validateSession?: (context: GuardContext) => boolean | Promise; /** Token refresh function */ readonly refreshToken?: () => Promise; /** Minimum session time before refresh (ms) */ readonly refreshThreshold?: number; /** Guard priority */ readonly priority?: number; /** Guard timeout */ readonly timeout?: number; /** Feature flag */ readonly featureFlag?: string; } /** * Authentication state */ export interface AuthState { /** Whether user is authenticated */ readonly isAuthenticated: boolean; /** Session expiry timestamp */ readonly expiresAt?: number; /** Whether session needs refresh */ readonly needsRefresh: boolean; /** Authentication error (if any) */ readonly error?: string; } /** * Default authentication guard configuration */ export declare const DEFAULT_AUTH_CONFIG: AuthGuardConfig; /** * Authentication route guard * * @example * ```typescript * const guard = new AuthGuard({ * loginPath: '/auth/login', * isAuthenticated: (ctx) => ctx.user?.isAuthenticated ?? false, * }); * * // Add to route * const result = await guard.execute('canActivate', context); * ``` */ export declare class AuthGuard extends BaseRouteGuard { private readonly authConfig; constructor(config?: AuthGuardConfig); /** * Get authentication state for a context */ getAuthState(context: GuardContext): Promise; /** * Check if a specific path requires authentication */ requiresAuth(path: string): boolean; /** * Get public paths configuration */ getPublicPaths(): readonly string[]; /** * Get login path */ getLoginPath(): string; /** * Check authentication status */ private checkAuthentication; /** * Check if user is authenticated */ private checkAuthStatus; /** * Check if path is public */ private isPublicPath; /** * Build redirect to login page */ private buildLoginRedirect; /** * Check if token needs refresh */ private checkTokenRefresh; } /** * Create an authentication guard * * @param config - Guard configuration * @returns AuthGuard instance */ export declare function createAuthGuard(config?: AuthGuardConfig): AuthGuard; /** * Create a simple auth guard from an authentication check function * * @param isAuthenticated - Function to check authentication * @param options - Additional options * @returns AuthGuard instance */ export declare function createSimpleAuthGuard(isAuthenticated: (context: GuardContext) => boolean | Promise, options?: Partial): AuthGuard; /** * Create an auth guard with token-based authentication * * @param options - Configuration options * @returns AuthGuard instance */ export declare function createTokenAuthGuard(options: { getToken: () => string | null; validateToken?: (token: string) => boolean | Promise; refreshToken?: () => Promise; loginPath?: string; }): AuthGuard; /** * Build a return URL for login redirect * * @param currentPath - Current path * @param query - Current query params * @param preserveQuery - Whether to preserve query params * @returns Encoded return URL */ export declare function buildReturnUrl(currentPath: string, query?: Record, preserveQuery?: boolean): string; /** * Parse return URL from query parameters * * @param query - Query parameters * @param paramName - Parameter name for return URL * @returns Decoded return URL or undefined */ export declare function parseReturnUrl(query: Record, paramName?: string): string | undefined; /** * Check if a path requires authentication based on patterns * * @param path - Path to check * @param publicPaths - Public path patterns * @returns True if path requires authentication */ export declare function pathRequiresAuth(path: string, publicPaths: readonly string[]): boolean; /** * Type guard for AuthGuard */ export declare function isAuthGuard(value: unknown): value is AuthGuard; /** * Type guard for AuthState */ export declare function isAuthState(value: unknown): value is AuthState;