import type { InstantReactWebDatabase } from "@instantdb/react" import { useEffect } from "react" import { instantAuth } from "../shared/instant-auth" import type { MinimalAuthClient, SessionResult } from "./types" import { usePersistentSession } from "./use-persistent-session" export interface InstantAuthProps { db: InstantReactWebDatabase authClient: MinimalAuthClient persistent?: boolean } export function useInstantAuth({ db, authClient, persistent }: InstantAuthProps) { const { isPending, data } = persistent ? usePersistentSession(authClient) : authClient.useSession() useEffect(() => { if (isPending) return instantAuth(db, data?.session) }, [db, isPending, data?.session]) }