diff --git a/README.md b/README.md index f6bfb4e..58e76a0 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ import ReCaptchaV3 from '@haskkor/react-native-recaptchav3' |**`captchaDomain`**|Your url registered with Google reCAPTCHA|`None`|`true`|`string`| |**`onReceiveToken`**|The callback used to get the captcha token from the component|`None`|`true`|`(captchaToken: string) => void`| |**`siteKey`**|The site key provided by Google reCAPTCHA|`None`|`true`|`string`| +|**`action`**|Optional recaptcha v3 action ([see documentation](https://developers.google.com/recaptcha/docs/v3#actions))|`None`|`false`|`string`| ## [Changelog](https://github.com/Haskkor/react-native-recaptchav3/blob/master/CHANGELOG.md) diff --git a/dist/index.d.ts b/dist/index.d.ts index 1021f24..c8beed9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -3,7 +3,7 @@ export declare type IProps = { captchaDomain: string; onReceiveToken: (captchaToken: string) => void; siteKey: string; - action: string; + action?: string; }; export declare type IState = {}; declare class ReCaptchaV3 extends React.PureComponent { diff --git a/dist/src/ReCaptchaComponent.d.ts b/dist/src/ReCaptchaComponent.d.ts index e508ae9..3c4866e 100644 --- a/dist/src/ReCaptchaComponent.d.ts +++ b/dist/src/ReCaptchaComponent.d.ts @@ -3,7 +3,7 @@ declare type IProps = { captchaDomain: string; onReceiveToken: (captchaToken: string) => void; siteKey: string; - action: string; + action?: string; }; declare class ReCaptchaComponent extends React.PureComponent { private _webViewRef; diff --git a/dist/src/ReCaptchaComponent.js b/dist/src/ReCaptchaComponent.js index c814d3e..01eba48 100644 --- a/dist/src/ReCaptchaComponent.js +++ b/dist/src/ReCaptchaComponent.js @@ -13,7 +13,8 @@ const patchPostMessageJsCode = `(${String(function () { window.postMessage = patchedPostMessage; })})();`; const getExecutionFunction = (siteKey, action) => { - return `window.grecaptcha.execute('${siteKey}', { action: '${action}' }).then( + const actionParam = action ? `{ action: '${action}' }` : '{}'; + return `window.grecaptcha.execute('${siteKey}', ${actionParam}).then( function(args) { window.ReactNativeWebView.postMessage(args); } diff --git a/index.tsx b/index.tsx index d6cbc1d..55e70f8 100644 --- a/index.tsx +++ b/index.tsx @@ -5,7 +5,7 @@ export type IProps = { captchaDomain: string onReceiveToken: (captchaToken: string) => void siteKey: string - action: string + action?: string } export type IState = {} diff --git a/package.json b/package.json index e14f528..85fc271 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@haskkor/react-native-recaptchav3", - "version": "1.2.1", + "version": "1.2.2", "description": "React native component to use the invisible recaptcha v3 from Google", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/ReCaptchaComponent.tsx b/src/ReCaptchaComponent.tsx index dddd8a2..0107404 100644 --- a/src/ReCaptchaComponent.tsx +++ b/src/ReCaptchaComponent.tsx @@ -8,7 +8,7 @@ type IProps = { captchaDomain: string onReceiveToken: (captchaToken: string) => void siteKey: string - action: string + action?: string } const patchPostMessageJsCode = `(${String(function () { @@ -20,15 +20,16 @@ const patchPostMessageJsCode = `(${String(function () { window.postMessage = patchedPostMessage })})();` -const getExecutionFunction = (siteKey: string, action: string) => { - return `window.grecaptcha.execute('${siteKey}', { action: '${action}' }).then( +const getExecutionFunction = (siteKey: string, action?: string) => { + const actionParam = action ? `{ action: '${action}' }` : '{}'; + return `window.grecaptcha.execute('${siteKey}', ${actionParam}).then( function(args) { window.ReactNativeWebView.postMessage(args); } )` } -const getInvisibleRecaptchaContent = (siteKey: string, action: string) => { +const getInvisibleRecaptchaContent = (siteKey: string, action?: string) => { return ` diff --git a/yarn.lock b/yarn.lock index d1a0bca..1959a5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3311,10 +3311,10 @@ react-devtools-core@^3.4.0: shell-quote "^1.6.1" ws "^3.3.1" -react-native-webview@^7.1.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/react-native-webview/-/react-native-webview-7.1.0.tgz#f05327e7f807c7897baac490c997f10bc108c59a" - integrity sha512-1MlIN/kUd2lWUU1iDQ0YuttGxxFGfco2ha4GzqanFsi8IvFjjRcLmAZnhLS1vyAA6G0yHBfforUIseO9mVgulQ== +react-native-webview@^9.0.1: + version "9.4.0" + resolved "https://registry.yarnpkg.com/react-native-webview/-/react-native-webview-9.4.0.tgz#108da34a6c7e1c032dcabc942b7e4947ca1d8028" + integrity sha512-BBOFUuza0p04+7fNi7TJmB0arpDJzGxHYwTCgI4vj5n/fl7u4jbm7ETp88mf7lo9lP6C6HGLo38KnEy1aXCQkg== dependencies: escape-string-regexp "2.0.0" invariant "2.2.4" @@ -3608,9 +3608,9 @@ sax@~1.1.1: resolved "http://registry.npmjs.org/sax/-/sax-1.1.6.tgz#5d616be8a5e607d54e114afae55b7eaf2fcc3240" scheduler@^16.6.2: - version "0.15.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e" - integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg== + version "0.20.1" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.1.tgz#da0b907e24026b01181ecbc75efdc7f27b5a000c" + integrity sha512-LKTe+2xNJBNxu/QhHvDR14wUXHRQbVY5ZOYpOGWRzhydZUqrLb2JBvLPY7cAqFmqrWuDED0Mjk7013SZiOz6Bw== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1"