Skip to content

Instantly share code, notes, and snippets.

@danieldsf
Created July 20, 2021 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldsf/9bf2a8ebf0c802689f48b118ad3962ba to your computer and use it in GitHub Desktop.
Save danieldsf/9bf2a8ebf0c802689f48b118ad3962ba to your computer and use it in GitHub Desktop.
const axios = require('axios');
class RecaptchaService{
constructor(secret){
this.secret = secret;
}
setResponse(response){
this.response = response || '';
return this;
}
get isValid(){
return this.response;
}
async sendRequest(){
try {
if(this.isValid){
let response = await axios.post(
`https://www.google.com/recaptcha/api/siteverify?secret=${this.secret}&response=${this.response}`,
{},
{
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
},
},
).then(data => data.data);
console.log(response);
return response.success;
}else{
return false;
}
} catch (error) {
console.log(error);
return false;
}
}
}
module.exports = { RecaptchaService };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment