fx-1 / src /hooks /useRecaptcha.ts
felix-fx's picture
Initial commit from GitHub fx-1
6711fd5 verified
Raw History Blame Contribute Delete
772 Bytes
/**
* Hook for Google reCAPTCHA v3 (invisible, score-based)
* If score is low, triggers fallback to custom CAPTCHA
*/
const RECAPTCHA_SITE_KEY = '6LeMr4wsAAAAAHVy6EPzSHVjMdvuExr6Naky3KQS';
declare global {
interface Window {
grecaptcha: {
ready: (cb: () => void) => void;
execute: (siteKey: string, options: { action: string }) => Promise<string>;
};
}
}
export const executeRecaptcha = (action: string): Promise<string> => {
return new Promise((resolve, reject) => {
if (!window.grecaptcha) {
reject(new Error('reCAPTCHA not loaded'));
return;
}
window.grecaptcha.ready(() => {
window.grecaptcha
.execute(RECAPTCHA_SITE_KEY, { action })
.then(resolve)
.catch(reject);
});
});
};