← Files FingerprintARCHIVED FILE

skills/fingerprint-nextjs/snippets/identify-on-action.tsx

759 Bytes · Oct 3, 2026 · 06:27 UTC

↓ Download file

// A client component: identify at the moment of a sensitive action and send event_id to the
// server. immediate: false → don't identify on mount; only when we call getData().
'use client'

import { useVisitorData } from '@fingerprint/react'

export function LoginForm() {
  const { getData } = useVisitorData({ immediate: false })

  async function handleSubmit(e: React.FormEvent) {
    e.preventDefault()
    const { event_id } = await getData()

    // Send the event_id (single-use, server-verifiable) — not the visitor_id.
    await fetch('/api/login', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ username, password, eventId: event_id }),
    })
  }

  return /* ...form... */ null
}

SHA-256: 6d553607f08af426f19cd21ea7361d5d394f42f51fb6e4d84f55fe82d85db755