Skip to content

Commit f4e3b87

Browse files
committed
added missing action props
1 parent aa9e73b commit f4e3b87

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export declare type IProps = {
33
captchaDomain: string;
44
onReceiveToken: (captchaToken: string) => void;
55
siteKey: string;
6+
action: string;
67
};
78
export declare type IState = {};
89
declare class ReCaptchaV3 extends React.PureComponent<IProps, IState> {

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ReCaptchaV3 extends React.PureComponent {
1010
};
1111
}
1212
render() {
13-
return (React.createElement(ReCaptchaComponent_1.default, { ref: ref => this._captchaRef = ref, captchaDomain: this.props.captchaDomain, siteKey: this.props.siteKey, onReceiveToken: (token) => {
13+
return (React.createElement(ReCaptchaComponent_1.default, { ref: ref => this._captchaRef = ref, action: this.props.action, captchaDomain: this.props.captchaDomain, siteKey: this.props.siteKey, onReceiveToken: (token) => {
1414
this.props.onReceiveToken(token);
1515
} }));
1616
}

dist/src/ReCaptchaComponent.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare type IProps = {
33
captchaDomain: string;
44
onReceiveToken: (captchaToken: string) => void;
55
siteKey: string;
6+
action: string;
67
};
78
declare class ReCaptchaComponent extends React.PureComponent<IProps> {
89
private _webViewRef;

dist/src/ReCaptchaComponent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ const patchPostMessageJsCode = `(${String(function () {
1212
patchedPostMessage.toString = () => String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
1313
window.postMessage = patchedPostMessage;
1414
})})();`;
15-
const getExecutionFunction = (siteKey) => {
16-
return `window.grecaptcha.execute('${siteKey}', { action: 'login' }).then(
15+
const getExecutionFunction = (siteKey, action) => {
16+
return `window.grecaptcha.execute('${siteKey}', { action: '${action}' }).then(
1717
function(args) {
1818
window.ReactNativeWebView.postMessage(args);
1919
}
2020
)`;
2121
};
22-
const getInvisibleRecaptchaContent = (siteKey) => {
22+
const getInvisibleRecaptchaContent = (siteKey, action) => {
2323
return `<!DOCTYPE html><html><head>
2424
<script src="https://www.google.com/recaptcha/api.js?render=${siteKey}"></script>
25-
<script>window.grecaptcha.ready(function() { ${getExecutionFunction(siteKey)} });</script>
25+
<script>window.grecaptcha.ready(function() { ${getExecutionFunction(siteKey, action)} });</script>
2626
</head></html>`;
2727
};
2828
class ReCaptchaComponent extends React.PureComponent {
@@ -32,7 +32,7 @@ class ReCaptchaComponent extends React.PureComponent {
3232
}
3333
refreshToken() {
3434
if (constants_1.platform.isIOS && this._webViewRef) {
35-
this._webViewRef.injectJavaScript(getExecutionFunction(this.props.siteKey));
35+
this._webViewRef.injectJavaScript(getExecutionFunction(this.props.siteKey, this.props.action));
3636
}
3737
else if (constants_1.platform.isAndroid && this._webViewRef) {
3838
this._webViewRef.reload();
@@ -43,7 +43,7 @@ class ReCaptchaComponent extends React.PureComponent {
4343
React.createElement(react_native_webview_1.WebView, { ref: (ref) => {
4444
this._webViewRef = ref;
4545
}, javaScriptEnabled: true, originWhitelist: ['*'], automaticallyAdjustContentInsets: true, mixedContentMode: 'always', injectedJavaScript: patchPostMessageJsCode, source: {
46-
html: getInvisibleRecaptchaContent(this.props.siteKey),
46+
html: getInvisibleRecaptchaContent(this.props.siteKey, this.props.action),
4747
baseUrl: this.props.captchaDomain
4848
}, onMessage: (e) => {
4949
this.props.onReceiveToken(e.nativeEvent.data);

index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type IProps = {
55
captchaDomain: string
66
onReceiveToken: (captchaToken: string) => void
77
siteKey: string
8+
action: string
89
}
910

1011
export type IState = {}
@@ -22,6 +23,7 @@ class ReCaptchaV3 extends React.PureComponent<IProps, IState> {
2223
return (
2324
<ReCaptchaComponent
2425
ref={ref => this._captchaRef = ref}
26+
action={this.props.action}
2527
captchaDomain={this.props.captchaDomain}
2628
siteKey={this.props.siteKey}
2729
onReceiveToken={(token: string) => {

src/ReCaptchaComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const getExecutionFunction = (siteKey: string, action: string) => {
2828
)`
2929
}
3030

31-
const getInvisibleRecaptchaContent = (siteKey: string) => {
31+
const getInvisibleRecaptchaContent = (siteKey: string, action: string) => {
3232
return `<!DOCTYPE html><html><head>
3333
<script src="https://www.google.com/recaptcha/api.js?render=${siteKey}"></script>
34-
<script>window.grecaptcha.ready(function() { ${getExecutionFunction(siteKey)} });</script>
34+
<script>window.grecaptcha.ready(function() { ${getExecutionFunction(siteKey, action)} });</script>
3535
</head></html>`
3636
}
3737

@@ -59,7 +59,7 @@ class ReCaptchaComponent extends React.PureComponent<IProps> {
5959
mixedContentMode={'always'}
6060
injectedJavaScript={patchPostMessageJsCode}
6161
source={{
62-
html: getInvisibleRecaptchaContent(this.props.siteKey),
62+
html: getInvisibleRecaptchaContent(this.props.siteKey, this.props.action),
6363
baseUrl: this.props.captchaDomain
6464
}}
6565
onMessage={(e: any) => {

0 commit comments

Comments
 (0)