@consumidor-positivo/ts-utils - v1.13.0
    Preparing search index...

    Function getRecaptchaAnswer

    • Executes a reCAPTCHA verification and retrieves the token.

      This function uses the reCAPTCHA Enterprise API to execute a verification for a specific action. It requires the reCAPTCHA script to be loaded and ready in the browser.

      Parameters

      • publicKey: string

        The public key for reCAPTCHA.

      • action: RecaptchaAction = 'LOGIN'

        The action to verify (default is 'LOGIN').

      Returns Promise<string>

      A promise that resolves to the reCAPTCHA token.

      import { getRecaptchaAnswer } from '@consumidor-positivo/ts-utils/operations';

      async function verifyUser() {
      const publicKey = 'your-public-key';
      const action = 'LOGIN';

      try {
      const token = await getRecaptchaAnswer(publicKey, action);
      console.log('reCAPTCHA token:', token);
      } catch (error) {
      console.error('reCAPTCHA verification failed:', error);
      }
      }

      Will throw an error if the public key is missing, the script is not loaded, or execution fails.