Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make action optional | Update README.md #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProps, IState> {
Expand Down
2 changes: 1 addition & 1 deletion dist/src/ReCaptchaComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProps> {
private _webViewRef;
Expand Down
3 changes: 2 additions & 1 deletion dist/src/ReCaptchaComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type IProps = {
captchaDomain: string
onReceiveToken: (captchaToken: string) => void
siteKey: string
action: string
action?: string
}

export type IState = {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 5 additions & 4 deletions src/ReCaptchaComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type IProps = {
captchaDomain: string
onReceiveToken: (captchaToken: string) => void
siteKey: string
action: string
action?: string
}

const patchPostMessageJsCode = `(${String(function () {
Expand All @@ -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 `<!DOCTYPE html><html><head>
<script src="https://www.google.com/recaptcha/api.js?render=${siteKey}"></script>
<script>window.grecaptcha.ready(function() { ${getExecutionFunction(siteKey, action)} });</script>
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down