Source: captcha/index.js

  1. /**
  2. * @module captcha
  3. */
  4. const got = require('got');
  5. /**
  6. * Verify reCAPTCHA response via Google reCAPTCHA API.
  7. * Return true if successfully verified.
  8. * @param {String} captchaResponse
  9. * @return {Boolean} true if verified
  10. */
  11. const verifyResponse = async (captchaResponse) => {
  12. const {body} = await got.post("https://www.google.com/recaptcha/api/siteverify", {
  13. responseType: "json",
  14. searchParams: {
  15. secret: process.env.GOOGLE_RECAPTCHA_SECRET,
  16. response: captchaResponse,
  17. },
  18. });
  19. return body.success;
  20. };
  21. module.exports = {
  22. verifyResponse,
  23. };