@descope/web-components-ui 1.0.336 → 1.0.338

Sign up to get free protection for your applications and to get access to all the features.
@@ -13007,6 +13007,53 @@ class RawRecaptcha extends BaseClass {
13007
13007
  return this.enterprise ? window.grecaptcha?.enterprise : window.grecaptcha;
13008
13008
  }
13009
13009
 
13010
+ #getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId) {
13011
+ if (!this.isConnected) {
13012
+ return;
13013
+ }
13014
+
13015
+ grecaptchaInstance.ready(() => {
13016
+ // clone the node and append it to the body so that it can be used by the grepcaptcha script
13017
+ const cloneNode = currentNode
13018
+ .querySelector('textarea[name^="g-recaptcha-response"]')
13019
+ ?.cloneNode();
13020
+ if (cloneNode) {
13021
+ cloneNode.style.display = 'none';
13022
+ document.body.appendChild(cloneNode);
13023
+ }
13024
+
13025
+ // cleaning up the recaptcha element we added to the body
13026
+ const removeCloneNode = () => {
13027
+ cloneNode.remove();
13028
+ };
13029
+
13030
+ if (!this.siteKey) {
13031
+ return;
13032
+ }
13033
+ // we should pass recaptchaWidgetId, but this does not allow us to run execute multiple times
13034
+ // also calling grecaptchaInstance.reset() does not work
13035
+ const exec = grecaptchaInstance?.execute(recaptchaWidgetId, { action: this.action });
13036
+ exec.then((token, e) => {
13037
+ if (e) {
13038
+ // eslint-disable-next-line no-console
13039
+ console.warn('could not execute recaptcha', e);
13040
+ } else {
13041
+ this.updateComponentsContext({
13042
+ risktoken: token,
13043
+ riskaction: this.action,
13044
+ });
13045
+ // if the component is still connected, we should try to get a new token before the token expires (2 minutes)
13046
+ if (this.isConnected) {
13047
+ setTimeout(() => {
13048
+ this.#getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId);
13049
+ }, 110000);
13050
+ }
13051
+ }
13052
+ removeCloneNode();
13053
+ });
13054
+ });
13055
+ }
13056
+
13010
13057
  #createOnLoadScript() {
13011
13058
  window.onRecaptchaLoadCallback = () => {
13012
13059
  const currentNode = this.recaptchaEle;
@@ -13023,48 +13070,12 @@ class RawRecaptcha extends BaseClass {
13023
13070
  }
13024
13071
 
13025
13072
  setTimeout(() => {
13026
- // returns recaptchaWidgetId
13027
13073
  const recaptchaWidgetId = grecaptchaInstance.render(currentNode, {
13028
13074
  sitekey: this.siteKey,
13029
13075
  badge: 'inline',
13030
13076
  size: 'invisible',
13031
13077
  });
13032
-
13033
- grecaptchaInstance.ready(() => {
13034
- // clone the node and append it to the body so that it can be used by the grepcaptcha script
13035
- const cloneNode = currentNode
13036
- .querySelector('textarea[name^="g-recaptcha-response"]')
13037
- ?.cloneNode();
13038
- if (cloneNode) {
13039
- cloneNode.style.display = 'none';
13040
- document.body.appendChild(cloneNode);
13041
- }
13042
-
13043
- // cleaning up the recaptcha element we added to the body
13044
- const removeCloneNode = () => {
13045
- cloneNode.remove();
13046
- };
13047
-
13048
- if (this.siteKey) {
13049
- // we should pass recaptchaWidgetId, but this does not allow us to run execute multiple times
13050
- // also calling grecaptchaInstance.reset() does not work
13051
- const exec = grecaptchaInstance?.execute(recaptchaWidgetId, { action: this.action });
13052
- exec
13053
- .then((token) => {
13054
- this.updateComponentsContext({
13055
- risktoken: token,
13056
- riskaction: this.action,
13057
- });
13058
-
13059
- removeCloneNode();
13060
- })
13061
- .catch((e) => {
13062
- removeCloneNode();
13063
- // eslint-disable-next-line no-console
13064
- console.warn('could not execute recaptcha', e);
13065
- });
13066
- }
13067
- });
13078
+ this.#getNewToken(grecaptchaInstance, currentNode, recaptchaWidgetId);
13068
13079
  }, 0);
13069
13080
  };
13070
13081
  }