Download frontend/src/components/datafast-identity.tsx from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 892 Bytes
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/components/datafast-identity.tsx
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/components/datafast-identity.tsx
-
curl -L -o datafast-identity.tsx https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/components/datafast-identity.tsx
892 Bytes
| "use client"; | |
| import { useEffect, useRef } from "react"; | |
| import { useSession } from "@/lib/auth-client"; | |
| import { identify } from "@/lib/datafast"; | |
| export function DataFastIdentity() { | |
| const { data: session } = useSession(); | |
| const lastPayloadRef = useRef<string | null>(null); | |
| useEffect(() => { | |
| const user = session?.user; | |
| if (!user?.id) { | |
| lastPayloadRef.current = null; | |
| return; | |
| } | |
| const payload = { | |
| user_id: user.id, | |
| ...(user.name ? { name: user.name } : {}), | |
| ...(user.image ? { image: user.image } : {}), | |
| is_admin: String(Boolean((user as { is_admin?: boolean }).is_admin)), | |
| }; | |
| const serializedPayload = JSON.stringify(payload); | |
| if (serializedPayload === lastPayloadRef.current) { | |
| return; | |
| } | |
| identify(payload); | |
| lastPayloadRef.current = serializedPayload; | |
| }, [session?.user]); | |
| return null; | |
| } | |