37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
/**
|
|
* Provides the Turnstile site key once for the whole app, like ConsentProvider
|
|
* for cookies. The project reads the key server-side and passes it here in the
|
|
* layout; forms then use <TurnstileWidget /> + useTurnstile() with NO per-form
|
|
* key wiring.
|
|
*
|
|
* // layout.tsx (server) → read key, pass to provider
|
|
* import { TurnstileProvider } from '@intecion/ipal-kit/client'
|
|
* const siteKey = await getTurnstileSiteKey() // your server helper
|
|
* <TurnstileProvider siteKey={siteKey}>{children}</TurnstileProvider>
|
|
*
|
|
* When siteKey is null (Turnstile not configured), widgets render nothing and
|
|
* token stays null — forms should treat "no Turnstile" as allowed in dev.
|
|
*/
|
|
export declare function TurnstileProvider({ siteKey, children, }: {
|
|
siteKey: string | null;
|
|
children: React.ReactNode;
|
|
}): import("react/jsx-runtime").JSX.Element;
|
|
/**
|
|
* Hook giving a form the Turnstile token + a widget bound to the provider's key.
|
|
* No per-form siteKey plumbing — the provider supplies it.
|
|
*
|
|
* const { token, TurnstileWidget, reset } = useTurnstile()
|
|
* // in JSX: <TurnstileWidget />
|
|
* // at submit: submitForm({ ..., turnstileToken: token })
|
|
* // after submit: reset() // clear for the next submission
|
|
*/
|
|
export declare function useTurnstile(): {
|
|
token: string | null;
|
|
TurnstileWidget: (props?: {
|
|
theme?: 'light' | 'dark' | 'auto';
|
|
}) => React.ReactNode;
|
|
reset: () => void;
|
|
/** True when Turnstile is configured (site key present). */
|
|
enabled: boolean;
|
|
};
|