Skip to content

Instantly share code, notes, and snippets.

@ANTOSzbk
Created March 31, 2020 19:48
Show Gist options
  • Save ANTOSzbk/75ed7003e914162550f61399122a3bd4 to your computer and use it in GitHub Desktop.
Save ANTOSzbk/75ed7003e914162550f61399122a3bd4 to your computer and use it in GitHub Desktop.
Commented code solved Uncaught (in promise) Timeout
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