0.1.0-alpha-5 • Published 6 months ago

@mcaptcha/core-glue v0.1.0-alpha-5

Weekly downloads
-
License
(MIT OR Apache-2....
Repository
github
Last release
6 months ago

NPM 0.1.0 Build) codecov

Usage

A custom glue implementation

  const instanceUrl = "https://api.mcaptcha.org";
  const siteKey: g.SiteKey = {
    key: "randomSitekeyasShowninmCaptchaDashboard",
    instanceUrl: new URL(instanceUrl),
  };

  /** callback function to update hidden input field. Varies for each
   * framework/ glue implementation
   */
  const cb = (token: string): void {
	  let input = document.getElementById("mcaptcha__token");
	  if (input) {
		  input.value =  token;
	  }
  }

  const config: g.WidgetConfig = {
    siteKey,
  };

  const r = new Receiver(config, cb.setToken);

  // register listener when component is mounted/necessary HTML for
  // callback function is rendered
  r.listen();

  // teardown
  r.destroy();