27

I'm trying to combine "firebase phone authentication" with ionic.

but, stuck in one question.

I keep getting "Hostname match not found" error from

.catch(function (error) { 
  console.log("error! : " +  error); 
});"

of login.ts(below)

import { Component } from '@angular/core';
import { IonicPage, NavController, AlertController } from 'ionic-angular';

import firebase from 'firebase';

@IonicPage()
@Component({
   selector: 'page-login',
   templateUrl: 'login.html',
})

export class LoginPage {
  public recaptchaVerifier:firebase.auth.RecaptchaVerifier;
  constructor(public navCtrl: NavController, public alertCtrl: AlertController) {}

  ionViewDidLoad() {
    this.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-
    container');
  }

  signIn(phoneNumber: number){
    const appVerifier = this.recaptchaVerifier;
    const phoneNumberString = "+" + phoneNumber;

    firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
      .then( confirmationResult => {

        let prompt = this.alertCtrl.create({
        title: 'Enter the Confirmation code',
        inputs: [{ name: 'confirmationCode', placeholder: 'Confirmation Code' }],
        buttons: [
          { text: 'Cancel',
            handler: data => { console.log('Cancel clicked'); }
          },
          { text: 'Send',
            handler: data => {
               confirmationResult.confirm(data.confirmationCode)
                 .then(function (result) {

                 }).catch(function (error) {

                 });
            }
          }
        ]
     });
     prompt.present();
   })
   .catch(function (error) {
      console.log("error! : " +  error);           //   <------------The place that informs this error.
   });
 }
}

this error occurred shortly after reCAPTCHA solved

Why does this happen?

--Initializing Firebase

enter image description here

--login.html

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
mr5
  • 281
  • 1
  • 3
  • 5

6 Answers6

75

This error may occur when you host your app in no ssl certified domain. Then you have to whitelist your domain in firebase console.

Go to Firebase Console -> Authentication -> sign-in-method -> Authorized Domains and add your domain.

By default localhostand any https:// domain is whitelisted.

Add any subdomain that you are currently using to test this app.

Vinod D
  • 3
  • 4
Hareesh
  • 6,770
  • 4
  • 33
  • 60
  • 1
    Unfortunately, my domain("my-project-name.firebaseapp.com") was added automatically in Authorized Domains when i activated Authentication Provider(Phone) in Console...TT – mr5 Oct 05 '17 at 11:35
  • 1
    I had to whitelist both www.mydomain.com and mydomain.com – kip2 Dec 20 '19 at 16:54
  • Waited 2 days to figure it out. There was another option to define the domain inside Google Developer for firebase account and that was not working at all. Thanks – Braj Oct 20 '20 at 07:14
  • 3
    In Oct 2022 it's `Firebase Console` -> `Authentication` -> **`Settings`**-> `Authorized Domains` – Touré Holder Oct 28 '22 at 02:25
15

This error occurs because when Google send otp on Number then it match your website url and your firebase Authentication url is your domain or site address match then it send you otp otherwise error occour.

To resolve the error, go to firebase console.

  1. Go firebase console.

  2. Click Authentication.

  3. Click SIGN-IN METHOD.

  4. Scroll down and check Authorized domains.

  5. Add your site address where you implement phone Authentication.

Pang
  • 9,564
  • 146
  • 81
  • 122
Pawan Kumar
  • 734
  • 9
  • 14
  • 1
    Thanks, This worked for me, I have updated the domain name in authorized domain list and captcha issue solved instantly – Vino Sep 22 '18 at 15:22
  • I added the domain in the authorized domains but still its not working any other information? – Manmeet Khurana Nov 29 '19 at 21:39
7

You should follow in here:

Note: The domain need to add both: https://www.exam.com and exam.com

To resolve the error, go to firebase console.

  1. Go firebase console.

  2. Click Authentication.

  3. Click SIGN-IN METHOD.

  4. Scroll down and check Authorized domains.

  5. Add your site address where you implement phone Authentication.

Alex
  • 3,646
  • 1
  • 28
  • 25
6

For new firebase Dashboard

Go to Firebase > Select your Project > Authentication > Settings and under domain you will find Authorise Domains.

Input the domain you want to add and save

shine odigie
  • 156
  • 1
  • 6
5

Go to Firebase > Select your Project > Authentication > Sign in method > Scroll Down -> Add your domain under 'Authorize Domain' section.

Follow the photo instruction :

enter image description here

enter image description here

XpressGeek
  • 2,889
  • 3
  • 23
  • 27
0

You can find your answer in this link: https://stackoverflow.com/a/44091221/6120430
Unfortunately, phone authentication using Firebase JS library will not work in a Cordova/Ionic...

Suhail Kawsara
  • 466
  • 3
  • 11