capacitor-plugin-recaptcha
Version:
Capacitor plugin for reCAPTCHA Enterprise
45 lines (38 loc) • 1.7 kB
JavaScript
var capacitorRecaptchaEnterprise = (function (exports, core, recaptchaV3) {
'use strict';
const CapacitorPluginRecaptcha$1 = core.registerPlugin('RecaptchaEnterprise', {
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorPluginRecaptcha()),
});
class CapacitorPluginRecaptcha extends core.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 recaptchaV3.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)}`);
}
}
}
var web = /*#__PURE__*/Object.freeze({
__proto__: null,
CapacitorPluginRecaptcha: CapacitorPluginRecaptcha
});
exports.CapacitorPluginRecaptcha = CapacitorPluginRecaptcha$1;
return exports;
})({}, capacitorExports, recaptchaV3);
//# sourceMappingURL=plugin.js.map