UNPKG

vue-recaptcha

Version:

ReCAPTCHA vue component

50 lines (49 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecaptchaContextKey = void 0; exports.normalizeOptions = normalizeOptions; exports.useAssertV2SiteKey = useAssertV2SiteKey; exports.useAssertV3SiteKey = useAssertV3SiteKey; exports.useRecaptchaContext = useRecaptchaContext; exports.useRecaptchaProxy = useRecaptchaProxy; var _vueDemi = require("vue-demi"); var _utils = require("../utils.cjs"); const RecaptchaContextKey = "vue-recaptcha-context"; exports.RecaptchaContextKey = RecaptchaContextKey; function useRecaptchaContext() { const context = (0, _vueDemi.inject)(RecaptchaContextKey); if (!context) { (0, _utils.warn)("You may forget to `use` vue-recaptcha plugin"); throw new Error("useRecaptcha() is called without provider."); } return context; } function useRecaptchaProxy() { const ctx = useRecaptchaContext(); return ctx.proxy; } function useAssertV2SiteKey() { const ctx = useRecaptchaContext(); (0, _utils.invariant)(ctx.options.v2SiteKey, "Your config is not compatible with recaptcha v2, please provide v2SiteKey"); return ctx.options.v2SiteKey; } function useAssertV3SiteKey() { const ctx = useRecaptchaContext(); (0, _utils.invariant)(ctx.options.v3SiteKey, "Your config is not compatible with recaptcha v3, please provide v3SiteKey"); return ctx.options.v3SiteKey; } function normalizeOptions(input) { (0, _utils.invariant)(input.v2SiteKey || input.v3SiteKey, "You didn't pass v2SiteKey or v3SiteKey to plugin, which may be a mistake"); return { ...input, loaderOptions: { ...input.loaderOptions, params: { ...input.loaderOptions?.params, render: input.v3SiteKey ?? "explicit" } } }; }