Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3b23fc7

Browse files
authored
Merge pull request #1106 from matrix-org/dbkr/reset_captcha_on_unmount
Make sure captcha disappears when container does
2 parents 56eb71d + 2a01e63 commit 3b23fc7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/components/views/login/CaptchaForm.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ module.exports = React.createClass({
4646
};
4747
},
4848

49+
componentWillMount: function() {
50+
this._captchaWidgetId = null;
51+
},
52+
4953
componentDidMount: function() {
5054
// Just putting a script tag into the returned jsx doesn't work, annoyingly,
5155
// so we do this instead.
@@ -75,6 +79,10 @@ module.exports = React.createClass({
7579
}
7680
},
7781

82+
componentWillUnmount: function() {
83+
this._resetRecaptcha();
84+
},
85+
7886
_renderRecaptcha: function(divId) {
7987
if (!global.grecaptcha) {
8088
console.error("grecaptcha not loaded!");
@@ -90,12 +98,18 @@ module.exports = React.createClass({
9098
}
9199

92100
console.log("Rendering to %s", divId);
93-
global.grecaptcha.render(divId, {
101+
this._captchaWidgetId = global.grecaptcha.render(divId, {
94102
sitekey: publicKey,
95103
callback: this.props.onCaptchaResponse,
96104
});
97105
},
98106

107+
_resetRecaptcha: function() {
108+
if (this._captchaWidgetId !== null) {
109+
global.grecaptcha.reset(this._captchaWidgetId);
110+
}
111+
},
112+
99113
_onCaptchaLoaded: function() {
100114
console.log("Loaded recaptcha script.");
101115
try {

0 commit comments

Comments
 (0)