teqo-backup/src/components/campaign/auth/useCampaignBiometricsAvailable.ts
Francisco Ignácio Fontoura Solla 763f64080a Deliver B40: biometric login for /campanha.
WebAuthn platform passkeys: opt-in enrollment after a password login, a
password-less sign-in that mints the same 14-day campaign-token, and
revocation from the profile. The session is minted through Payload's public
pieces (checkLoginPermission, addSessionToUser, getFieldsToSign, jwtSign)
inside a transaction with an advisory lock, so a passkey login neither
bypasses a lockout nor evicts the account's other sessions. The rpID is
derived from NEXT_PUBLIC_SITE_URL and resolves to null when the request host
disagrees, so previews never offer a ceremony the browser would refuse.
2026-07-28 10:59:23 -03:00

28 lines
827 B
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { canUseCampaignBiometrics } from '@/lib/campaignWebAuthnSupport'
/**
* Whether this browser can run a platform ceremony, resolved after mount
* because the probe is async and the server cannot answer it. Starts `false` so
* nothing biometric renders during hydration on a device that has no
* authenticator; the cancellation guard is the reason this is shared rather than
* written per island (B40 has two).
*/
export const useCampaignBiometricsAvailable = (): boolean => {
const [available, setAvailable] = useState(false)
useEffect(() => {
let active = true
void canUseCampaignBiometrics().then((supported) => {
if (active) setAvailable(supported)
})
return () => {
active = false
}
}, [])
return available
}