Created
March 31, 2020 19:48
-
-
Save ANTOSzbk/75ed7003e914162550f61399122a3bd4 to your computer and use it in GitHub Desktop.
Commented code solved Uncaught (in promise) Timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function captchaVerification() { | |
return await new Promise((resolve, reject) => { | |
const captcha = document.createElement('div') | |
captcha.setAttribute('id', 'g-recaptcha') | |
document.getElementById('main').appendChild(captcha) | |
const verifyCallback = async (response) => { | |
if (response) { | |
const data = { | |
token: response, | |
} | |
/* const verifyStatus = await fetch('app', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
redirect: 'manual', | |
body: JSON.stringify(data) | |
}) | |
if(verifyStatus) { | |
captcha.remove() | |
return resolve(true) | |
} | |
else return reject('Invalid captcha verification.') */ | |
return resolve(data) // We need to resolve promise anyway | |
} else { | |
grecaptcha.reset() | |
return reject('Invalid captcha verification.') | |
} | |
} | |
grecaptcha.render('g-recaptcha', { | |
'sitekey': '6LdFlOQUAAAAABdYGtt_xTVH4hj57fvCrRTgZcST', | |
'theme': 'dark', | |
'callback': verifyCallback | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment