import { useEffect, useRef } from "react"; import { usePlaidLink } from "react-plaid-link"; import { Button } from "@/components/ui/button"; /** One automatically opened Link session, shared by connect and reconnect. */ export function PlaidLinkSession({ token, onSuccess, onClose }: { token: string; onSuccess: (publicToken: string) => void; onClose: (failed?: boolean) => void; }) { const opened = useRef(false); const { open, ready, error } = usePlaidLink({ token, onSuccess, onExit: error => onClose(Boolean(error)), }); useEffect(() => { if (ready && !opened.current) { opened.current = true; open(); } }, [ready, open]); if (error) return
The secure bank window couldn't load. Refresh the page and try again.