[Vuejs]-How can I verify token google recaptcha 3 on adonis js?

0👍

You need to use axios. Something like:

const axios = use('axios')
const Env = use('Env')
const querystring = use('querystring')

async store({ request, response }) {
  const data = request.only(['token'])

  try {
    const data_request = await axios.post('https://www.google.com/recaptcha/api/siteverify', querystring.stringify({ secret: Env.get('RECAPTCHA_PRIVATE_KEY'), response: data['token'], remoteip: '172.217.23.110' }))
    if (!data_request.data.success) {
      //If the recaptcha check fails
      ...
    }
  } catch (error) {
    ...
  }
}

Google documentation – Verifying the user’s response

This code is made for v2. But the verification is the same : https://developers.google.com/recaptcha/docs/v3#site_verify_response

Leave a comment