UNPKG

@flavoai/fastfold

Version:

Flavo frontend package

101 lines 3.78 kB
import React from 'react'; export interface FlavoUser { email: string; displayName: string; avatar: string; authProvider: string; meta?: Record<string, any>; } export interface FlavoAuthState { user: FlavoUser | null; isLoading: boolean; isAuthenticated: boolean; /** Initiate login. Redirects to the Flavo login page where the user picks their provider. */ login: () => void; logout: () => void; } export interface FlavoAuthConfig { enabled: boolean; /** The app/conversation ID. Required for shared-backend (direct login) mode. */ appId?: string; /** Override the login redirect URL. Defaults to https://flavo.ai */ loginBaseUrl?: string; /** Override the validate endpoint URL. Defaults to the Fastfold server's own proxy, or Flavo directly. */ validateUrl?: string; /** Called after successful login. */ onLogin?: (user: FlavoUser) => void; /** Called after logout. */ onLogout?: () => void; } /** * Hook to access Flavo auth state and actions. * Must be used within a FlavoAuthProvider. * * @example * function MyComponent() { * const { user, isAuthenticated, login, logout } = useFlavoAuth(); * if (!isAuthenticated) return <button onClick={login}>Sign in</button>; * return <div>Welcome, {user?.displayName}! <button onClick={logout}>Sign out</button></div>; * } */ export declare function useFlavoAuth(): FlavoAuthState; /** * Context provider that manages the Flavo auth lifecycle: * - Resolves the session from the httpOnly cookie on mount (via `/api/auth/me`) * - Provides login/logout actions * * @example * <FlavoAuthProvider> * <App /> * </FlavoAuthProvider> */ export declare function FlavoAuthProvider({ children, config, }: { children: React.ReactNode; config?: Partial<FlavoAuthConfig>; }): React.FunctionComponentElement<React.ProviderProps<FlavoAuthState | null>>; /** * Drop-in component for the OAuth callback route (/auth). Waits for the * provider to resolve the session cookie, then redirects to `redirectTo` on * success or `/login?error=auth_failed` on failure. * * Renders `loadingComponent` (or nothing, by default) while the session is * being validated. Style it to match the app's own theme so the transient * paint looks native to the app. * * @example * // In your router: * <Route path="/auth" element={<FlavoAuthCallback redirectTo="/app" loadingComponent={<AppSkeleton />} />} /> */ export declare function FlavoAuthCallback({ redirectTo, loadingComponent, }: { redirectTo?: string; loadingComponent?: React.ReactNode; }): React.ReactElement | null; /** * Wraps children and only renders them when the user is authenticated. * * While the session is being validated, renders `loadingComponent` — or * nothing at all if the caller didn't pass one. Style it to match the app's * own theme; a skeleton that mirrors the authenticated shell usually works * best because the refresh paint becomes a still frame of the real page. * * When unauthenticated with no `fallback`, triggers `login()` and renders * `loadingComponent` (or nothing) while the browser navigates to the Flavo * login page. * * @example * <ProtectedRoute fallback={<LoginPage />} loadingComponent={<AppSkeleton />}> * <Dashboard /> * </ProtectedRoute> * * @example * // Auto-redirect to login when unauthenticated * <ProtectedRoute loadingComponent={<AppSkeleton />}> * <Dashboard /> * </ProtectedRoute> */ export declare function ProtectedRoute({ children, fallback, loadingComponent, }: { children: React.ReactNode; fallback?: React.ReactNode; loadingComponent?: React.ReactNode; }): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null; //# sourceMappingURL=auth.d.ts.map