@hcaptcha/react-hcaptcha 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/esm/index.js +37 -23
- package/dist/index.js +39 -23
- package/package.json +1 -1
- package/src/index.js +36 -16
package/README.md
CHANGED
|
@@ -192,9 +192,16 @@ Please note that "invisible" simply means that no hCaptcha button will be render
|
|
|
192
192
|
3. #### Make sure you are using `reCaptchaCompat=false` if you have the reCAPTCHA JS loaded on the same page.
|
|
193
193
|
The hCaptcha "compatibility mode" will interfere with reCAPTCHA, as it adds properties with the same name. If for any reason you are running both hCaptcha and reCAPTCHA in parallel (we recommend only running hCaptcha) then please disable our compatibility mode.
|
|
194
194
|
|
|
195
|
-
4. #### Avoid conflicts with legacy Sentry package usage on react-hcaptcha 1.9.0+
|
|
196
|
-
If you are using Sentry 7.x in your React app, this can conflict with the upstream `hcaptcha-loader` package's Sentry error tracing. You can avoid this issue by setting the `sentry` prop to `false`.
|
|
197
195
|
|
|
196
|
+
### Sentry
|
|
197
|
+
|
|
198
|
+
If the `sentry` flag is enabled, the upstream `hcaptcha-loader` package expects the Sentry SDK, version 8.x or later.
|
|
199
|
+
|
|
200
|
+
If you have an older `@sentry/browser` client version on your site, it may take precedence over the bundled version. In this case you may see a console error like "g.setPropagationContext is not a function" due to the hcaptcha-loader trying to call methods only available on newer Sentry clients.
|
|
201
|
+
|
|
202
|
+
To resolve this, update the version of the Sentry client you are including on your site to 8.x or higher.
|
|
203
|
+
|
|
204
|
+
You can avoid this issue by setting the `sentry` prop to `false`.
|
|
198
205
|
|
|
199
206
|
|
|
200
207
|
---
|
package/dist/esm/index.js
CHANGED
|
@@ -37,11 +37,11 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
37
37
|
_this.ref = /*#__PURE__*/React.createRef();
|
|
38
38
|
_this.apiScriptRequested = false;
|
|
39
39
|
_this.sentryHub = null;
|
|
40
|
+
_this.captchaId = '';
|
|
40
41
|
_this.state = {
|
|
41
42
|
isApiReady: false,
|
|
42
43
|
isRemoved: false,
|
|
43
|
-
elementId: props.id
|
|
44
|
-
captchaId: ''
|
|
44
|
+
elementId: props.id
|
|
45
45
|
};
|
|
46
46
|
return _this;
|
|
47
47
|
}
|
|
@@ -75,8 +75,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
75
75
|
this.loadCaptcha();
|
|
76
76
|
};
|
|
77
77
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
78
|
-
var captchaId = this.state.captchaId;
|
|
79
78
|
var hcaptcha = this._hcaptcha;
|
|
79
|
+
var captchaId = this.captchaId;
|
|
80
80
|
if (!this.isReady()) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
@@ -154,10 +154,16 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
154
154
|
hCaptchaLoader(mountParams).then(this.handleOnLoad, this.handleError)["catch"](this.handleError);
|
|
155
155
|
this.apiScriptRequested = true;
|
|
156
156
|
};
|
|
157
|
-
_proto.renderCaptcha = function renderCaptcha(
|
|
157
|
+
_proto.renderCaptcha = function renderCaptcha(onRender) {
|
|
158
158
|
var _this4 = this;
|
|
159
|
+
var onReady = this.props.onReady;
|
|
159
160
|
var isApiReady = this.state.isApiReady;
|
|
160
|
-
|
|
161
|
+
var captchaId = this.captchaId;
|
|
162
|
+
|
|
163
|
+
// Prevent calling hCaptcha render on two conditions:
|
|
164
|
+
// • API is not ready
|
|
165
|
+
// • Component has already been mounted
|
|
166
|
+
if (!isApiReady || captchaId) return;
|
|
161
167
|
var renderParams = Object.assign({
|
|
162
168
|
"open-callback": this.handleOpen,
|
|
163
169
|
"close-callback": this.handleClose,
|
|
@@ -171,18 +177,19 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
171
177
|
});
|
|
172
178
|
var hcaptcha = this._hcaptcha;
|
|
173
179
|
//Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
174
|
-
var
|
|
180
|
+
var id = hcaptcha.render(this.ref.current, renderParams);
|
|
181
|
+
this.captchaId = id;
|
|
175
182
|
this.setState({
|
|
176
|
-
isRemoved: false
|
|
177
|
-
captchaId: captchaId
|
|
183
|
+
isRemoved: false
|
|
178
184
|
}, function () {
|
|
185
|
+
onRender && onRender();
|
|
179
186
|
onReady && onReady();
|
|
180
|
-
_this4._onReady && _this4._onReady(
|
|
187
|
+
_this4._onReady && _this4._onReady(id);
|
|
181
188
|
});
|
|
182
189
|
};
|
|
183
190
|
_proto.resetCaptcha = function resetCaptcha() {
|
|
184
|
-
var captchaId = this.state.captchaId;
|
|
185
191
|
var hcaptcha = this._hcaptcha;
|
|
192
|
+
var captchaId = this.captchaId;
|
|
186
193
|
if (!this.isReady()) {
|
|
187
194
|
return;
|
|
188
195
|
}
|
|
@@ -194,8 +201,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
194
201
|
});
|
|
195
202
|
};
|
|
196
203
|
_proto.removeCaptcha = function removeCaptcha(callback) {
|
|
197
|
-
var captchaId = this.state.captchaId;
|
|
198
204
|
var hcaptcha = this._hcaptcha;
|
|
205
|
+
var captchaId = this.captchaId;
|
|
199
206
|
if (!this.isReady()) {
|
|
200
207
|
return;
|
|
201
208
|
}
|
|
@@ -234,10 +241,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
234
241
|
};
|
|
235
242
|
_proto.handleSubmit = function handleSubmit(event) {
|
|
236
243
|
var onVerify = this.props.onVerify;
|
|
237
|
-
var
|
|
238
|
-
isRemoved = _this$state.isRemoved,
|
|
239
|
-
captchaId = _this$state.captchaId;
|
|
244
|
+
var isRemoved = this.state.isRemoved;
|
|
240
245
|
var hcaptcha = this._hcaptcha;
|
|
246
|
+
var captchaId = this.captchaId;
|
|
241
247
|
if (typeof hcaptcha === 'undefined' || isRemoved) return;
|
|
242
248
|
var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget
|
|
243
249
|
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
@@ -245,8 +251,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
245
251
|
};
|
|
246
252
|
_proto.handleExpire = function handleExpire() {
|
|
247
253
|
var onExpire = this.props.onExpire;
|
|
248
|
-
var captchaId = this.state.captchaId;
|
|
249
254
|
var hcaptcha = this._hcaptcha;
|
|
255
|
+
var captchaId = this.captchaId;
|
|
250
256
|
if (!this.isReady()) {
|
|
251
257
|
return;
|
|
252
258
|
}
|
|
@@ -260,8 +266,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
260
266
|
};
|
|
261
267
|
_proto.handleError = function handleError(event) {
|
|
262
268
|
var onError = this.props.onError;
|
|
263
|
-
var captchaId = this.state.captchaId;
|
|
264
269
|
var hcaptcha = this._hcaptcha;
|
|
270
|
+
var captchaId = this.captchaId;
|
|
265
271
|
if (this.isReady()) {
|
|
266
272
|
// If hCaptcha runs into error, reset captcha - hCaptcha
|
|
267
273
|
hcaptcha.reset(captchaId);
|
|
@@ -269,9 +275,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
269
275
|
if (onError) onError(event);
|
|
270
276
|
};
|
|
271
277
|
_proto.isReady = function isReady() {
|
|
272
|
-
var _this$
|
|
273
|
-
isApiReady = _this$
|
|
274
|
-
isRemoved = _this$
|
|
278
|
+
var _this$state = this.state,
|
|
279
|
+
isApiReady = _this$state.isApiReady,
|
|
280
|
+
isRemoved = _this$state.isRemoved;
|
|
275
281
|
return isApiReady && !isRemoved;
|
|
276
282
|
};
|
|
277
283
|
_proto.handleOpen = function handleOpen() {
|
|
@@ -299,8 +305,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
299
305
|
}
|
|
300
306
|
opts = typeof opts === 'object' ? opts : null;
|
|
301
307
|
try {
|
|
302
|
-
var captchaId = this.state.captchaId;
|
|
303
308
|
var hcaptcha = this._hcaptcha;
|
|
309
|
+
var captchaId = this.captchaId;
|
|
304
310
|
if (!this.isReady()) {
|
|
305
311
|
var _opts;
|
|
306
312
|
var onReady = new Promise(function (resolve, reject) {
|
|
@@ -328,9 +334,17 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
328
334
|
return null;
|
|
329
335
|
}
|
|
330
336
|
};
|
|
337
|
+
_proto.close = function close() {
|
|
338
|
+
var hcaptcha = this._hcaptcha;
|
|
339
|
+
var captchaId = this.captchaId;
|
|
340
|
+
if (!this.isReady()) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
return hcaptcha.close(captchaId);
|
|
344
|
+
};
|
|
331
345
|
_proto.setData = function setData(data) {
|
|
332
|
-
var captchaId = this.state.captchaId;
|
|
333
346
|
var hcaptcha = this._hcaptcha;
|
|
347
|
+
var captchaId = this.captchaId;
|
|
334
348
|
if (!this.isReady()) {
|
|
335
349
|
return;
|
|
336
350
|
}
|
|
@@ -341,11 +355,11 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
341
355
|
};
|
|
342
356
|
_proto.getResponse = function getResponse() {
|
|
343
357
|
var hcaptcha = this._hcaptcha;
|
|
344
|
-
return hcaptcha.getResponse(this.
|
|
358
|
+
return hcaptcha.getResponse(this.captchaId);
|
|
345
359
|
};
|
|
346
360
|
_proto.getRespKey = function getRespKey() {
|
|
347
361
|
var hcaptcha = this._hcaptcha;
|
|
348
|
-
return hcaptcha.getRespKey(this.
|
|
362
|
+
return hcaptcha.getRespKey(this.captchaId);
|
|
349
363
|
};
|
|
350
364
|
_proto.render = function render() {
|
|
351
365
|
var elementId = this.state.elementId;
|
package/dist/index.js
CHANGED
|
@@ -55,11 +55,11 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
55
55
|
_this.ref = /*#__PURE__*/React.createRef();
|
|
56
56
|
_this.apiScriptRequested = false;
|
|
57
57
|
_this.sentryHub = null;
|
|
58
|
+
_this.captchaId = '';
|
|
58
59
|
_this.state = {
|
|
59
60
|
isApiReady: false,
|
|
60
61
|
isRemoved: false,
|
|
61
|
-
elementId: props.id
|
|
62
|
-
captchaId: ''
|
|
62
|
+
elementId: props.id
|
|
63
63
|
};
|
|
64
64
|
return _this;
|
|
65
65
|
}
|
|
@@ -96,8 +96,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
96
96
|
}, {
|
|
97
97
|
key: "componentWillUnmount",
|
|
98
98
|
value: function componentWillUnmount() {
|
|
99
|
-
var captchaId = this.state.captchaId;
|
|
100
99
|
var hcaptcha = this._hcaptcha;
|
|
100
|
+
var captchaId = this.captchaId;
|
|
101
101
|
if (!this.isReady()) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
@@ -183,10 +183,16 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
183
183
|
}
|
|
184
184
|
}, {
|
|
185
185
|
key: "renderCaptcha",
|
|
186
|
-
value: function renderCaptcha(
|
|
186
|
+
value: function renderCaptcha(onRender) {
|
|
187
187
|
var _this4 = this;
|
|
188
|
+
var onReady = this.props.onReady;
|
|
188
189
|
var isApiReady = this.state.isApiReady;
|
|
189
|
-
|
|
190
|
+
var captchaId = this.captchaId;
|
|
191
|
+
|
|
192
|
+
// Prevent calling hCaptcha render on two conditions:
|
|
193
|
+
// • API is not ready
|
|
194
|
+
// • Component has already been mounted
|
|
195
|
+
if (!isApiReady || captchaId) return;
|
|
190
196
|
var renderParams = Object.assign({
|
|
191
197
|
"open-callback": this.handleOpen,
|
|
192
198
|
"close-callback": this.handleClose,
|
|
@@ -200,20 +206,21 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
200
206
|
});
|
|
201
207
|
var hcaptcha = this._hcaptcha;
|
|
202
208
|
//Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
203
|
-
var
|
|
209
|
+
var id = hcaptcha.render(this.ref.current, renderParams);
|
|
210
|
+
this.captchaId = id;
|
|
204
211
|
this.setState({
|
|
205
|
-
isRemoved: false
|
|
206
|
-
captchaId: captchaId
|
|
212
|
+
isRemoved: false
|
|
207
213
|
}, function () {
|
|
214
|
+
onRender && onRender();
|
|
208
215
|
onReady && onReady();
|
|
209
|
-
_this4._onReady && _this4._onReady(
|
|
216
|
+
_this4._onReady && _this4._onReady(id);
|
|
210
217
|
});
|
|
211
218
|
}
|
|
212
219
|
}, {
|
|
213
220
|
key: "resetCaptcha",
|
|
214
221
|
value: function resetCaptcha() {
|
|
215
|
-
var captchaId = this.state.captchaId;
|
|
216
222
|
var hcaptcha = this._hcaptcha;
|
|
223
|
+
var captchaId = this.captchaId;
|
|
217
224
|
if (!this.isReady()) {
|
|
218
225
|
return;
|
|
219
226
|
}
|
|
@@ -227,8 +234,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
227
234
|
}, {
|
|
228
235
|
key: "removeCaptcha",
|
|
229
236
|
value: function removeCaptcha(callback) {
|
|
230
|
-
var captchaId = this.state.captchaId;
|
|
231
237
|
var hcaptcha = this._hcaptcha;
|
|
238
|
+
var captchaId = this.captchaId;
|
|
232
239
|
if (!this.isReady()) {
|
|
233
240
|
return;
|
|
234
241
|
}
|
|
@@ -271,10 +278,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
271
278
|
key: "handleSubmit",
|
|
272
279
|
value: function handleSubmit(event) {
|
|
273
280
|
var onVerify = this.props.onVerify;
|
|
274
|
-
var
|
|
275
|
-
isRemoved = _this$state.isRemoved,
|
|
276
|
-
captchaId = _this$state.captchaId;
|
|
281
|
+
var isRemoved = this.state.isRemoved;
|
|
277
282
|
var hcaptcha = this._hcaptcha;
|
|
283
|
+
var captchaId = this.captchaId;
|
|
278
284
|
if (typeof hcaptcha === 'undefined' || isRemoved) return;
|
|
279
285
|
var token = hcaptcha.getResponse(captchaId); //Get response token from hCaptcha widget
|
|
280
286
|
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
@@ -284,8 +290,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
284
290
|
key: "handleExpire",
|
|
285
291
|
value: function handleExpire() {
|
|
286
292
|
var onExpire = this.props.onExpire;
|
|
287
|
-
var captchaId = this.state.captchaId;
|
|
288
293
|
var hcaptcha = this._hcaptcha;
|
|
294
|
+
var captchaId = this.captchaId;
|
|
289
295
|
if (!this.isReady()) {
|
|
290
296
|
return;
|
|
291
297
|
}
|
|
@@ -301,8 +307,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
301
307
|
key: "handleError",
|
|
302
308
|
value: function handleError(event) {
|
|
303
309
|
var onError = this.props.onError;
|
|
304
|
-
var captchaId = this.state.captchaId;
|
|
305
310
|
var hcaptcha = this._hcaptcha;
|
|
311
|
+
var captchaId = this.captchaId;
|
|
306
312
|
if (this.isReady()) {
|
|
307
313
|
// If hCaptcha runs into error, reset captcha - hCaptcha
|
|
308
314
|
hcaptcha.reset(captchaId);
|
|
@@ -312,9 +318,9 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
312
318
|
}, {
|
|
313
319
|
key: "isReady",
|
|
314
320
|
value: function isReady() {
|
|
315
|
-
var _this$
|
|
316
|
-
isApiReady = _this$
|
|
317
|
-
isRemoved = _this$
|
|
321
|
+
var _this$state = this.state,
|
|
322
|
+
isApiReady = _this$state.isApiReady,
|
|
323
|
+
isRemoved = _this$state.isRemoved;
|
|
318
324
|
return isApiReady && !isRemoved;
|
|
319
325
|
}
|
|
320
326
|
}, {
|
|
@@ -348,8 +354,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
348
354
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
349
355
|
opts = (0, _typeof2["default"])(opts) === 'object' ? opts : null;
|
|
350
356
|
try {
|
|
351
|
-
var captchaId = this.state.captchaId;
|
|
352
357
|
var hcaptcha = this._hcaptcha;
|
|
358
|
+
var captchaId = this.captchaId;
|
|
353
359
|
if (!this.isReady()) {
|
|
354
360
|
var _opts;
|
|
355
361
|
var onReady = new Promise(function (resolve, reject) {
|
|
@@ -377,11 +383,21 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
377
383
|
return null;
|
|
378
384
|
}
|
|
379
385
|
}
|
|
386
|
+
}, {
|
|
387
|
+
key: "close",
|
|
388
|
+
value: function close() {
|
|
389
|
+
var hcaptcha = this._hcaptcha;
|
|
390
|
+
var captchaId = this.captchaId;
|
|
391
|
+
if (!this.isReady()) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
return hcaptcha.close(captchaId);
|
|
395
|
+
}
|
|
380
396
|
}, {
|
|
381
397
|
key: "setData",
|
|
382
398
|
value: function setData(data) {
|
|
383
|
-
var captchaId = this.state.captchaId;
|
|
384
399
|
var hcaptcha = this._hcaptcha;
|
|
400
|
+
var captchaId = this.captchaId;
|
|
385
401
|
if (!this.isReady()) {
|
|
386
402
|
return;
|
|
387
403
|
}
|
|
@@ -394,13 +410,13 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
394
410
|
key: "getResponse",
|
|
395
411
|
value: function getResponse() {
|
|
396
412
|
var hcaptcha = this._hcaptcha;
|
|
397
|
-
return hcaptcha.getResponse(this.
|
|
413
|
+
return hcaptcha.getResponse(this.captchaId);
|
|
398
414
|
}
|
|
399
415
|
}, {
|
|
400
416
|
key: "getRespKey",
|
|
401
417
|
value: function getRespKey() {
|
|
402
418
|
var hcaptcha = this._hcaptcha;
|
|
403
|
-
return hcaptcha.getRespKey(this.
|
|
419
|
+
return hcaptcha.getRespKey(this.captchaId);
|
|
404
420
|
}
|
|
405
421
|
}, {
|
|
406
422
|
key: "render",
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -37,12 +37,12 @@ class HCaptcha extends React.Component {
|
|
|
37
37
|
this.ref = React.createRef();
|
|
38
38
|
this.apiScriptRequested = false;
|
|
39
39
|
this.sentryHub = null;
|
|
40
|
+
this.captchaId = '';
|
|
40
41
|
|
|
41
42
|
this.state = {
|
|
42
43
|
isApiReady: false,
|
|
43
44
|
isRemoved: false,
|
|
44
45
|
elementId: props.id,
|
|
45
|
-
captchaId: ''
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -82,8 +82,8 @@ class HCaptcha extends React.Component {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
componentWillUnmount() {
|
|
85
|
-
const { captchaId } = this.state;
|
|
86
85
|
const hcaptcha = this._hcaptcha;
|
|
86
|
+
const captchaId = this.captchaId;
|
|
87
87
|
|
|
88
88
|
if (!this.isReady()) {
|
|
89
89
|
return;
|
|
@@ -170,9 +170,15 @@ class HCaptcha extends React.Component {
|
|
|
170
170
|
this.apiScriptRequested = true;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
renderCaptcha(
|
|
173
|
+
renderCaptcha(onRender) {
|
|
174
|
+
const { onReady } = this.props;
|
|
174
175
|
const { isApiReady } = this.state;
|
|
175
|
-
|
|
176
|
+
const captchaId = this.captchaId;
|
|
177
|
+
|
|
178
|
+
// Prevent calling hCaptcha render on two conditions:
|
|
179
|
+
// • API is not ready
|
|
180
|
+
// • Component has already been mounted
|
|
181
|
+
if (!isApiReady || captchaId) return;
|
|
176
182
|
|
|
177
183
|
const renderParams = Object.assign({
|
|
178
184
|
"open-callback" : this.handleOpen,
|
|
@@ -188,17 +194,19 @@ class HCaptcha extends React.Component {
|
|
|
188
194
|
|
|
189
195
|
const hcaptcha = this._hcaptcha;
|
|
190
196
|
//Render hCaptcha widget and provide necessary callbacks - hCaptcha
|
|
191
|
-
const
|
|
197
|
+
const id = hcaptcha.render(this.ref.current, renderParams);
|
|
198
|
+
this.captchaId = id;
|
|
192
199
|
|
|
193
|
-
this.setState({ isRemoved: false
|
|
200
|
+
this.setState({ isRemoved: false }, () => {
|
|
201
|
+
onRender && onRender();
|
|
194
202
|
onReady && onReady();
|
|
195
|
-
this._onReady && this._onReady(
|
|
203
|
+
this._onReady && this._onReady(id);
|
|
196
204
|
});
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
resetCaptcha() {
|
|
200
|
-
const { captchaId } = this.state;
|
|
201
208
|
const hcaptcha = this._hcaptcha;
|
|
209
|
+
const captchaId = this.captchaId;
|
|
202
210
|
|
|
203
211
|
if (!this.isReady()) {
|
|
204
212
|
return;
|
|
@@ -213,8 +221,8 @@ class HCaptcha extends React.Component {
|
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
removeCaptcha(callback) {
|
|
216
|
-
const { captchaId } = this.state;
|
|
217
224
|
const hcaptcha = this._hcaptcha;
|
|
225
|
+
const captchaId = this.captchaId;
|
|
218
226
|
|
|
219
227
|
if (!this.isReady()) {
|
|
220
228
|
return;
|
|
@@ -256,8 +264,9 @@ class HCaptcha extends React.Component {
|
|
|
256
264
|
|
|
257
265
|
handleSubmit (event) {
|
|
258
266
|
const { onVerify } = this.props;
|
|
259
|
-
const { isRemoved
|
|
267
|
+
const { isRemoved } = this.state;
|
|
260
268
|
const hcaptcha = this._hcaptcha;
|
|
269
|
+
const captchaId = this.captchaId;
|
|
261
270
|
|
|
262
271
|
if (typeof hcaptcha === 'undefined' || isRemoved) return
|
|
263
272
|
|
|
@@ -268,8 +277,8 @@ class HCaptcha extends React.Component {
|
|
|
268
277
|
|
|
269
278
|
handleExpire () {
|
|
270
279
|
const { onExpire } = this.props;
|
|
271
|
-
const { captchaId } = this.state;
|
|
272
280
|
const hcaptcha = this._hcaptcha;
|
|
281
|
+
const captchaId = this.captchaId;
|
|
273
282
|
|
|
274
283
|
if (!this.isReady()) {
|
|
275
284
|
return;
|
|
@@ -287,8 +296,8 @@ class HCaptcha extends React.Component {
|
|
|
287
296
|
|
|
288
297
|
handleError (event) {
|
|
289
298
|
const { onError } = this.props;
|
|
290
|
-
const { captchaId } = this.state;
|
|
291
299
|
const hcaptcha = this._hcaptcha;
|
|
300
|
+
const captchaId = this.captchaId;
|
|
292
301
|
|
|
293
302
|
if (this.isReady()) {
|
|
294
303
|
// If hCaptcha runs into error, reset captcha - hCaptcha
|
|
@@ -333,8 +342,8 @@ class HCaptcha extends React.Component {
|
|
|
333
342
|
opts = typeof opts === 'object' ? opts : null;
|
|
334
343
|
|
|
335
344
|
try {
|
|
336
|
-
const { captchaId } = this.state;
|
|
337
345
|
const hcaptcha = this._hcaptcha;
|
|
346
|
+
const captchaId = this.captchaId;
|
|
338
347
|
|
|
339
348
|
if (!this.isReady()) {
|
|
340
349
|
const onReady = new Promise((resolve, reject) => {
|
|
@@ -367,9 +376,20 @@ class HCaptcha extends React.Component {
|
|
|
367
376
|
}
|
|
368
377
|
}
|
|
369
378
|
|
|
379
|
+
close() {
|
|
380
|
+
const hcaptcha = this._hcaptcha;
|
|
381
|
+
const captchaId = this.captchaId;
|
|
382
|
+
|
|
383
|
+
if (!this.isReady()) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return hcaptcha.close(captchaId);
|
|
388
|
+
}
|
|
389
|
+
|
|
370
390
|
setData (data) {
|
|
371
|
-
const { captchaId } = this.state;
|
|
372
391
|
const hcaptcha = this._hcaptcha;
|
|
392
|
+
const captchaId = this.captchaId;
|
|
373
393
|
|
|
374
394
|
if (!this.isReady()) {
|
|
375
395
|
return;
|
|
@@ -384,12 +404,12 @@ class HCaptcha extends React.Component {
|
|
|
384
404
|
|
|
385
405
|
getResponse() {
|
|
386
406
|
const hcaptcha = this._hcaptcha;
|
|
387
|
-
return hcaptcha.getResponse(this.
|
|
407
|
+
return hcaptcha.getResponse(this.captchaId);
|
|
388
408
|
}
|
|
389
409
|
|
|
390
410
|
getRespKey() {
|
|
391
411
|
const hcaptcha = this._hcaptcha;
|
|
392
|
-
return hcaptcha.getRespKey(this.
|
|
412
|
+
return hcaptcha.getRespKey(this.captchaId)
|
|
393
413
|
}
|
|
394
414
|
|
|
395
415
|
render () {
|