UNPKG

vue-recaptcha

Version:

ReCAPTCHA vue component

27 lines (26 loc) 1 kB
import { ref } from "vue-demi"; import { RecaptchaContextKey, normalizeOptions } from "./composables/context.mjs"; import { createRecaptchaProxy } from "./composables/proxy.mjs"; import { checkRecaptchaLoad, recaptchaLoaded } from "./script-manager/common.mjs"; import { warn } from "./utils.mjs"; export function createPlugin(scriptLoaderFactory, { getRecaptcha = () => window.grecaptcha } = {}) { return { install(app, options) { const isReady = ref(false); async function waitLoaded() { await recaptchaLoaded.promise; isReady.value = true; } waitLoaded().catch((error) => warn("fail to load reCAPTCHA script", error)); checkRecaptchaLoad(); const opt = normalizeOptions(options); app.provide(RecaptchaContextKey, { isReady, scriptInjected: false, proxy: createRecaptchaProxy(isReady, getRecaptcha), useScriptProvider: scriptLoaderFactory(opt.loaderOptions), options: opt }); } }; }