dozoisch / react-google-recaptcha

Component wrapper for Google reCAPTCHA
MIT License
1.03k stars 142 forks source link

Support for Enterprise Action names #289

Open Miguelii opened 7 months ago

Miguelii commented 7 months ago

Since enterprise version is supported, how about adding support for the Enterprise Actions ?

Docs: https://cloud.google.com/recaptcha-enterprise/docs/actions-website .

Example (see data-action atribute) : https://developers.google.com/recaptcha/docs/v3.

I've already tested and its a easy change:

/src/recaptcha.js
explicitRender() {
    const render = this.getCaptchaFunction("render");
    if (render && this._widgetId === undefined) {

      const wrapper = document.createElement("div");

      wrapper.setAttribute("data-action", this.props.dataAction); // Change: Adding the atribute to the div, a new prop (dataAction) is necessary

      this._widgetId = render(wrapper, {
        sitekey: this.props.sitekey,
        callback: this.handleChange,
        theme: this.props.theme,
        type: this.props.type,
        tabindex: this.props.tabindex,
        "expired-callback": this.handleExpired,
        "error-callback": this.handleErrored,
        size: this.props.size,
        stoken: this.props.stoken,
        hl: this.props.hl,
        badge: this.props.badge,
        isolated: this.props.isolated,
        "data-action": this.props.dataAction, // Change: Pass the action also to the render
      });
      this.captcha.appendChild(wrapper);
    }
    ...
  }
9swampy commented 5 months ago

I've pushed a PR based on @Miguelii's suggestion; verbatim it didn't work for me because of the interjected div he had decorated. Even with the decoration it didn't work for me, but without as noted on the PR it works.

Out of interest what's the process for getting @types/react-google-recaptcha updated too this obviously changes the exposed API.