Firebase OTP SMS NOT SENT auth / operation-not-supported-in-environment

时间:2017-11-21 08:15:22

标签: firebase firebase-authentication ionic3 one-time-password

Firebase Phone Auth正在开发网络,但是在返回&#34时没有在Android设备上工作; SMS NOT SENT"错误和" auth / operation-not-supported-in-this-environment"消息

Recaptcha在网络上工作而不在Android手机上工作

和firebase安卓文档建议

编译com.google.firebase:firebase-auth:11.6.0' ---在build.gradle中添加

添加时&创建一个构建

编译依赖行从build.gradle消失

SMS not sent 
N {code: "auth/operation-not-supported-in-this-environment", message: "RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment."}
code
:"auth/operation-not-supported-in-this-environment"
message
:"RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment."
__proto__
:Error    

这是我的代码

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController} from 'ionic-angular';
import firebase from 'firebase';
/**
 * Generated class for the LoginPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@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',{
     'size':'invisible',
      'callback':function(responce){

      }
    });

  }

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

    firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
      .then( confirmationResult => {
        // SMS sent. Prompt user to type the code from the message, then sign the
        // user in with confirmationResult.confirm(code).
        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) {
                  var user = result.user;
                  // User signed in successfully.
                  console.log(result.user);
                  // ...
                }).catch(function (error) {
                  // User couldn't sign in (bad verification code?)
                  // ...
                });
            }
          }
        ]
      });
      prompt.present();
    })
    .catch(function (error) {
      console.error("SMS not sent", error);
    });

  }



}

0 个答案:

没有答案