Skip to content

Commit cdb2946

Browse files
fix: disable recaptcha when site key is not set (#5451)
# What this PR does Although recaptcha verification is disabled by default on the backend for OSS installs, the plugin was still making use of the site key and trying to load recaptcha. As that recaptcha site was removed this no longer works. The updated plugin code will skip recaptcha verification if it does not have a site key set. ## Which issue(s) this PR closes Related to #5449 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --------- Co-authored-by: GitHub Actions <[email protected]>
1 parent 615e152 commit cdb2946

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

grafana-plugin/src/containers/UserSettings/parts/tabs/PhoneVerification/PhoneVerification.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ export const PhoneVerification = observer((props: PhoneVerificationProps) => {
108108
await UserHelper.verifyPhone(userPk, code);
109109
userStore.fetchItemById({ userPk });
110110
} else {
111-
window.grecaptcha.ready(async function () {
112-
const token = await window.grecaptcha.execute(rootStore.recaptchaSiteKey, {
113-
action: 'mobile_verification_code',
114-
});
111+
async function start_verification(token) {
115112
await userStore.updateUser({
116113
pk: userPk,
117114
email: user.email,
@@ -121,20 +118,31 @@ export const PhoneVerification = observer((props: PhoneVerificationProps) => {
121118
switch (type) {
122119
case 'verification_call':
123120
await UserHelper.fetchVerificationCall(userPk, token);
124-
setState({ isPhoneCallInitiated: true });
121+
setState({isPhoneCallInitiated: true});
125122
if (codeInputRef.current) {
126123
codeInputRef.current.focus();
127124
}
128125
break;
129126
case 'verification_sms':
130127
await UserHelper.fetchVerificationCode(userPk, token);
131-
setState({ isCodeSent: true });
128+
setState({isCodeSent: true});
132129
if (codeInputRef.current) {
133130
codeInputRef.current.focus();
134131
}
135132
break;
136133
}
137-
});
134+
}
135+
136+
if (!rootStore.recaptchaSiteKey?.trim()) {
137+
await start_verification(null)
138+
} else {
139+
window.grecaptcha.ready(async function () {
140+
const token = await window.grecaptcha.execute(rootStore.recaptchaSiteKey, {
141+
action: 'mobile_verification_code',
142+
});
143+
await start_verification(token);
144+
});
145+
}
138146
}
139147
},
140148
[

0 commit comments

Comments
 (0)