3

I am using ng-recaptcha package in order to implement Google reCAPTCHA V3 in my web app. For that I created a Service with will perform all the needed actions on the client side.

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ReCaptchaV3Service, OnExecuteData } from 'ng-recaptcha';

import { environment } from 'src/environments/environment';


const BACKEND_URL = environment.apiUrl + '/contact/';

@Injectable()
export class ContactService {
    constructor(
        private http: HttpClient,
        private recaptchaV3Service: ReCaptchaV3Service
    ) {}

    public sendContactForm(data): void {
        this.recaptchaV3Service.execute('contactForm').subscribe(data => {
            console.log(data);
        });

        // this.http.post(BACKEND_URL, data)
        //     .subscribe((responseData) => {
        //         console.log(responseData);
        //     });
    }
}

Unfortunatelly, when executing recaptcha (on sendContactForm method), I get the following error:

"Uncaught (in promise): [object Null]"

enter image description here

What is wrong here?

Ron Rofe
  • 738
  • 1
  • 9
  • 25

2 Answers2

5

This errors occurs when a site is not "registered" in the Google recaptcha/admin Domains area.

Solution: Add the domain in the recaptcha admin area:

  1. Sign into your Google account where your recaptcha keys are registered
  2. Type into Google "google recpatcha admin console"
  3. Go to your settings for your (production) key
  4. In "Domains", add these two entries:
localhost
127.0.0.1
  1. Save it and test your recaptcha.

There is another question that asks the same thing and requires the same solution.

EliteRaceElephant
  • 7,744
  • 4
  • 47
  • 62
2

You need to add your domain to the recaptcha admin console.

Don't forget to add localhost for your test.

4b0
  • 21,981
  • 30
  • 95
  • 142
Mephisto
  • 21
  • 2