vue-recaptcha
Version:
ReCAPTCHA vue component
32 lines (31 loc) • 824 B
JavaScript
import { invariant } from "../utils.mjs";
import { recaptchaLoaded } from "../script-manager/common.mjs";
export function createRecaptchaProxy(isReady, getRecaptcha) {
function assertLoaded() {
invariant(isReady.value, "ReCAPTCHA is not loaded");
}
async function wait() {
await recaptchaLoaded.promise;
isReady.value = true;
}
return {
async render(ele, options) {
await wait();
return getRecaptcha().render(ele, options);
},
reset(widgetId) {
if (typeof widgetId === "undefined") {
return;
}
assertLoaded();
getRecaptcha().reset(widgetId);
},
async execute(widgetId, options) {
if (typeof widgetId === "undefined") {
return;
}
await wait();
return getRecaptcha().execute(widgetId, options);
}
};
}