Add recaptcha debugging

This commit is contained in:
Robert Long 2022-01-18 11:47:10 -08:00
parent f6b3d6830e
commit 36d59c98c0
2 changed files with 9 additions and 0 deletions

View file

@ -64,7 +64,9 @@ export function RegisterPage() {
if (isPasswordlessUser) { if (isPasswordlessUser) {
await changePassword(password); await changePassword(password);
} else { } else {
console.log("executing recaptcha");
const recaptchaResponse = await execute(); const recaptchaResponse = await execute();
console.log("recaptcha response", recaptchaResponse);
await register(userName, password, recaptchaResponse); await register(userName, password, recaptchaResponse);
} }
} }

View file

@ -22,6 +22,7 @@ export function useRecaptcha(sitekey) {
sitekey, sitekey,
size: "invisible", size: "invisible",
callback: (response) => { callback: (response) => {
console.log("callback", response);
if (promiseRef.current) { if (promiseRef.current) {
promiseRef.current.resolve(response); promiseRef.current.resolve(response);
} }
@ -53,10 +54,12 @@ export function useRecaptcha(sitekey) {
const execute = useCallback(() => { const execute = useCallback(() => {
if (!sitekey) { if (!sitekey) {
console.log("no site key");
return Promise.resolve(null); return Promise.resolve(null);
} }
if (!window.grecaptcha) { if (!window.grecaptcha) {
console.log("Recaptcha not loaded");
return Promise.reject(new Error("Recaptcha not loaded")); return Promise.reject(new Error("Recaptcha not loaded"));
} }
@ -64,6 +67,7 @@ export function useRecaptcha(sitekey) {
const observer = new MutationObserver((mutationsList) => { const observer = new MutationObserver((mutationsList) => {
for (const item of mutationsList) { for (const item of mutationsList) {
if (item.target.style?.visibility !== "visible") { if (item.target.style?.visibility !== "visible") {
console.log("Recaptcha dismissed");
reject(new Error("Recaptcha dismissed")); reject(new Error("Recaptcha dismissed"));
observer.disconnect(); observer.disconnect();
return; return;
@ -73,10 +77,12 @@ export function useRecaptcha(sitekey) {
promiseRef.current = { promiseRef.current = {
resolve: (value) => { resolve: (value) => {
console.log("Recaptcha resolved", value);
resolve(value); resolve(value);
observer.disconnect(); observer.disconnect();
}, },
reject: (error) => { reject: (error) => {
console.log("Recaptcha rejected", error);
reject(error); reject(error);
observer.disconnect(); observer.disconnect();
}, },
@ -98,6 +104,7 @@ export function useRecaptcha(sitekey) {
const reset = useCallback(() => { const reset = useCallback(() => {
if (window.grecaptcha) { if (window.grecaptcha) {
console.log("Recaptcha reset");
window.grecaptcha.reset(); window.grecaptcha.reset();
} }
}, [recaptchaId]); }, [recaptchaId]);