capacitor-plugin-recaptcha
Version:
Capacitor plugin for reCAPTCHA Enterprise
28 lines • 1.1 kB
JavaScript
import { WebPlugin } from '@capacitor/core';
import { load } from 'recaptcha-v3';
export class CapacitorPluginRecaptcha extends WebPlugin {
/**
* Loads the reCAPTCHA SDK for the given siteKey. Should be called during app startup.
* @param siteKey The reCAPTCHA site key to use.
*/
async load(options) {
this._recaptcha = await load(options.siteKey, { useEnterprise: true });
this._siteKey = options.siteKey;
}
/**
* Executes reCAPTCHA with the previously loaded siteKey. Throws if not loaded.
*/
async execute(options) {
if (!this._recaptcha || !this._siteKey) {
throw new Error('reCAPTCHA not loaded. Call load(siteKey) during app startup.');
}
try {
const token = await this._recaptcha.execute(options.action);
return { token, siteKey: this._siteKey };
}
catch (err) {
throw new Error(`reCAPTCHA execution failed: ${(err === null || err === void 0 ? void 0 : err.message) || JSON.stringify(err)}`);
}
}
}
//# sourceMappingURL=web.js.map