import { ReactNode } from 'react'; import { InitialAuthState, InsforgeProviderProps } from '@insforge/react'; interface InsforgeServerProviderProps extends Omit { children: ReactNode; /** * The base URL of your InsForge backend. * * @deprecated Use `InsforgeBrowserProvider` in a client component instead. * This prop is kept for backward compatibility only. */ baseUrl?: string; /** * The anonymous key for your InsForge backend. * * @deprecated Use `InsforgeBrowserProvider` in a client component instead. * This prop is kept for backward compatibility only. */ anonKey?: string; /** * Opt into dynamic rendering to read auth state from cookies during SSR. * * - When true: Reads cookies on server, prevents content flashing, opts into dynamic rendering * - When false: Static rendering, may see brief content flash during hydration * * @default true */ dynamic?: boolean; } /** * @deprecated Use `InsforgeServerProviderProps` instead. */ type InsforgeProviderServerProps = InsforgeServerProviderProps; /** * Get initial auth state from cookies (server-side) * * This helper reads the authentication state from cookies set by the SDK. * Use this in Server Components to get the initial auth state and pass it * to `InsforgeBrowserProvider` via the `initialState` prop. * * This prevents hydration mismatches by ensuring SSR and client render have the same state. * * @example * ```tsx * // app/layout.tsx (Server Component) * import { getAuthFromCookies } from '@insforge/nextjs'; * import { Providers } from './providers'; * * export default async function RootLayout({ children }) { * const initialState = await getAuthFromCookies(); * * return ( * * * * {children} * * * * ); * } * ``` * * @returns Initial auth state with user and userId, or null values if not authenticated */ declare function getAuthFromCookies(): Promise; /** * @deprecated **This component is deprecated.** Use `InsforgeBrowserProvider` instead. * * This Server Component wrapper doesn't work correctly because SDK client instances * (class objects) cannot be serialized and passed from Server to Client Components. * * --- * * ## Migration Guide * * ### Before (deprecated): * ```tsx * // app/layout.tsx * import { InsforgeServerProvider } from '@insforge/nextjs'; * import { insforge } from '@/lib/insforge'; * * export default function RootLayout({ children }) { * return ( * // ❌ This fails! * {children} * * ); * } * ``` * * ### After (recommended): * * **Step 1:** Create a client-side Providers component: * ```tsx * // app/providers.tsx * 'use client'; * import { InsforgeBrowserProvider, type InitialAuthState } from '@insforge/nextjs'; * import { insforge } from '@/lib/insforge'; * * export function Providers({ * children, * initialState, * }: { * children: React.ReactNode; * initialState?: InitialAuthState; * }) { * return ( * * {children} * * ); * } * ``` * * **Step 2:** Use it in your layout: * ```tsx * // app/layout.tsx * import { getAuthFromCookies } from '@insforge/nextjs'; * import { Providers } from './providers'; * * export default async function RootLayout({ children }) { * const initialState = await getAuthFromCookies(); * * return ( * * * * {children} * * * * ); * } * ``` * * --- * * @see InsforgeBrowserProvider - The recommended client-side provider * @see getAuthFromCookies - Helper to get initial auth state for SSR */ declare function InsforgeServerProvider(props: InsforgeServerProviderProps): Promise; /** * @deprecated Use `InsforgeServerProvider` instead (which is also deprecated). * Migrate to `InsforgeBrowserProvider` for proper Next.js App Router support. */ declare const InsforgeProvider: typeof InsforgeServerProvider; export { InsforgeProvider, type InsforgeProviderServerProps, InsforgeServerProvider, type InsforgeServerProviderProps, getAuthFromCookies };