diff options
Diffstat (limited to 'packages/lib')
| -rw-r--r-- | packages/lib/auth-context.tsx | 30 | ||||
| -rw-r--r-- | packages/lib/posthog.tsx | 29 |
2 files changed, 35 insertions, 24 deletions
diff --git a/packages/lib/auth-context.tsx b/packages/lib/auth-context.tsx index 7e6462fa..db24ec45 100644 --- a/packages/lib/auth-context.tsx +++ b/packages/lib/auth-context.tsx @@ -38,17 +38,23 @@ export function AuthProvider({ children }: { children: ReactNode }) { // biome-ignore lint/correctness/useExhaustiveDependencies: ignoring the setActiveOrg dependency useEffect(() => { if (session?.session.activeOrganizationId) { - authClient.organization.getFullOrganization().then((org) => { - // TODO: Uncomment this when we have a way to handle consumer organizations better way - //if (org.metadata?.isConsumer === true) { - setOrg(org) - //} else { - // const consumerOrg = orgs?.find((o) => o.metadata?.isConsumer === true) - // if (consumerOrg) { - // setActiveOrg(consumerOrg.slug) - // } - //} - }) + authClient.organization + .getFullOrganization() + .then((org) => { + // TODO: Uncomment this when we have a way to handle consumer organizations better way + //if (org.metadata?.isConsumer === true) { + setOrg(org) + //} else { + // const consumerOrg = orgs?.find((o) => o.metadata?.isConsumer === true) + // if (consumerOrg) { + // setActiveOrg(consumerOrg.slug) + // } + //} + }) + .catch((error) => { + // Silently handle organization fetch failures to prevent unhandled rejections + console.error("Failed to fetch organization:", error) + }) } }, [session?.session.activeOrganizationId, orgs]) @@ -68,7 +74,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { if (pendingMethod) { const now = Date.now() - const ts = pendingTsRaw ? Number.parseInt(pendingTsRaw, 10) : NaN + const ts = pendingTsRaw ? Number.parseInt(pendingTsRaw, 10) : Number.NaN const isFresh = Number.isFinite(ts) && now - ts < 10 * 60 * 1000 // 10 minutes TTL if (isFresh) { diff --git a/packages/lib/posthog.tsx b/packages/lib/posthog.tsx index 62a60e09..0c436e1e 100644 --- a/packages/lib/posthog.tsx +++ b/packages/lib/posthog.tsx @@ -22,7 +22,7 @@ function PostHogPageTracking() { $current_url: url, path: pathname, search_params: searchParams.toString(), - page_type: getPageType(pathname), + page_type: getPageType(), org_slug: getOrgSlug(pathname), } @@ -39,16 +39,21 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) { useEffect(() => { if (typeof window !== "undefined") { const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY - if (posthogKey){ - posthog.init(posthogKey, { - api_host: process.env.NEXT_PUBLIC_BACKEND_URL + "/orange", - ui_host: "https://us.i.posthog.com", - person_profiles: "identified_only", - capture_pageview: false, - capture_pageleave: true, - })} - else{ - console.warn("PostHog API key is not set. PostHog will not be initialized.") + const backendUrl = + process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai" + + if (posthogKey) { + posthog.init(posthogKey, { + api_host: `${backendUrl}/orange`, + ui_host: "https://us.i.posthog.com", + person_profiles: "identified_only", + capture_pageview: false, + capture_pageleave: true, + }) + } else { + console.warn( + "PostHog API key is not set. PostHog will not be initialized.", + ) } } }, []) @@ -75,7 +80,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) { ) } -function getPageType(pathname: string): string { +function getPageType(): string { return "other" } |