Spaces:
Running
Running
Download apps/web/src/components/FormbricksProvider.tsx from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/FormbricksProvider.tsx
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/web/src/components/FormbricksProvider.tsx
-
curl -L -o FormbricksProvider.tsx https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/components/FormbricksProvider.tsx
1.2 kB
| "use client"; | |
| import { useEffect, useState } from "react"; | |
| import { usePathname } from "next/navigation"; | |
| import formbricks from "@formbricks/js"; | |
| import { authClient } from "@/lib/auth-client"; | |
| export default function FormbricksProvider() { | |
| const pathname = usePathname(); | |
| const { data: session } = authClient.useSession(); | |
| // useSearchParams() throws during static prerendering without a Suspense boundary. | |
| // We only need it client-side for registerRouteChange, so initialize lazily. | |
| const [searchParams] = useState<URLSearchParams>(() => { | |
| if (typeof window !== "undefined") { | |
| return new URLSearchParams(window.location.search); | |
| } | |
| return new URLSearchParams(); | |
| }); | |
| useEffect(() => { | |
| formbricks.setup({ | |
| environmentId: process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID || "dev", | |
| appUrl: process.env.NEXT_PUBLIC_FORMBRICKS_APP_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000", | |
| }); | |
| }, []); | |
| useEffect(() => { | |
| if (session?.user?.id) { | |
| formbricks.setUserId(session.user.id); | |
| } | |
| }, [session?.user?.id]); | |
| useEffect(() => { | |
| formbricks?.registerRouteChange(); | |
| }, [pathname, searchParams]); | |
| return null; | |
| } | |