UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

111 lines 2.82 kB
import { AuthStatus, Session, User } from '@frank-auth/client'; import { FrankAuthConfig } from '../types'; export interface MiddlewareAuthState { isLoaded: boolean; isAuthenticated: boolean; user: User | null; session: Session | null; organizationId: string | null; error: Error | null; } export interface MiddlewareHookConfig extends FrankAuthConfig { /** * Enable automatic token refresh * @default true */ enableAutoRefresh?: boolean; /** * Refresh token interval in milliseconds * @default 300000 (5 minutes) */ refreshInterval?: number; /** * Redirect to sign in when unauthenticated * @default true */ redirectToSignIn?: boolean; /** * Sign in path for redirects * @default '/sign-in' */ signInPath?: string; /** * Enable debug logging * @default false */ debug?: boolean; } export interface AuthActions { /** * Manually refresh authentication state */ refresh: () => Promise<void>; /** * Sign out the current user */ signOut: () => Promise<void>; /** * Switch to a different organization */ switchOrganization: (organizationId: string) => Promise<void>; /** * Check if user has specific permission */ hasPermission: (permission: string) => Promise<boolean>; /** * Get fresh auth status from server */ getAuthStatus: () => Promise<AuthStatus>; } /** * Main authentication hook that works with middleware */ export declare function useAuth(): MiddlewareAuthState & AuthActions; /** * Hook for authentication state only */ export declare function useAuthState(): MiddlewareAuthState; /** * Hook for current user information */ export declare function useUser(): { user: User | null; isLoaded: boolean; error: Error | null; }; /** * Hook for session management */ export declare function useSession(): { session: Session | null; isLoaded: boolean; refresh: () => Promise<void>; signOut: () => Promise<void>; }; /** * Hook for organization management */ export declare function useOrganization(): { organizationId: string | null; switchOrganization: (organizationId: string) => Promise<void>; isLoaded: boolean; }; /** * Hook for permission checking */ export declare function usePermissions(): { hasPermission: (permission: string) => Promise<boolean>; checkPermissions: (permissions: string[]) => Promise<Record<string, boolean>>; }; /** * Hook for protected routes */ export declare function useProtectedRoute(options?: { redirectTo?: string; requiredPermission?: string; requiredOrganization?: boolean; }): { isLoaded: boolean; isAuthorized: boolean | null; }; //# sourceMappingURL=use-middleware.d.ts.map