我试图使用插件的电话认证离子,我发现这个链接:https://github.com/sajTempler/IonicFirebasePhoneAuth,默认情况下,国家代码硬编码为47,所以我把它改为55,这是我的CC,但我不确定是否有插件的问题,或者我只是没有正确键入它的号码,因为每次我试图注册我的电话号码,我得到以下错误的 chrome 检查页
registerPhone err验证号码时发生未知错误错误示例:com.google.firebase.FirebaseException
下面是代码
Login.ts
import {Component, ViewChild, OnInit} from '@angular/core';
import {IonicPage, NavController, AlertController} from 'ionic-angular';
import {AngularFireAuth} from '@angular/fire/auth';
import {Firebase} from '@ionic-native/firebase';
import * as firebase from 'firebase/app';
/**
* 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 implements OnInit {
@ViewChild('phoneNumber') phoneNumber;
constructor(
private navCtrl: NavController,
private fireAuth: AngularFireAuth,
private alertCtrl: AlertController,
private fire: Firebase,
) {
}
ngOnInit() {
console.log('LoginPage ngOnInit');
this.fireAuth.authState.subscribe(auth => {
if (!auth) {
return;
}
auth.getIdToken()
.then((token: string) => {
console.log('LoginPage getIdToken token', token);
if (token) {
this.doLogin();
}
});
});
}
// tslint:disable-next-line
private registerPhone(): void {
console.log('registerPhone');
const phone = '+55' + this.phoneNumber.value;
console.log('registerPhone phone', phone);
this.fire.verifyPhoneNumber(phone, 120)
.then((res) => {
const {verificationId} = res;
console.log('registerPhone verificationId', verificationId);
this.showPrompt(verificationId);
})
.catch(err => {
console.log('registerPhone err', err);
})
}
private async verifyCode(code: string, verificationId: string) {
try {
const credential = await firebase.auth.PhoneAuthProvider.credential(verificationId, code);
await firebase.auth().signInWithCredential(credential)
.then(() => {
this.doLogin();
})
.catch(err => {
console.error('LoginPage verifyCode signInWithCredential err', err);
})
} catch (err) {
console.error('LoginPage verifyCode err', err);
}
}
private showPrompt(verificationId: string) {
let promptCode = this.alertCtrl.create({
title: 'Verify',
message: 'Type code that was received via SMS',
inputs: [
{
name: 'code',
placeholder: 'Code'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
return;
}
},
{
text: 'Verify',
handler: data => {
this.verifyCode(data.code, verificationId);
}
}
]
});
promptCode.present();
}
private doLogin(): void {
this.navCtrl.setRoot('HomePage');
}
}
Login.html
<!--
Generated template for the LoginPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>Login</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div class="login-verify" id="recaptcha-container"></div>
<ion-list>
<ion-item>
<ion-label>+55</ion-label>
<ion-input #phoneNumber type="tel" maxlength="11"></ion-input>
</ion-item>
</ion-list>
</ion-content>
<ion-footer class="login-footer">
<button full ion-button class="login-btn" (click)="registerPhone()">Go</button>
</ion-footer>
输出如下:https://imgur.com/a/OjTdZVB
每次我尝试,我做:+CC接线员号码、电话号码,共11个号码。
1条答案
按热度按时间u4dcyp6a1#
您是否检查过您的Android应用google-services.json文件中的project_id是否与您启用了Google登录身份验证的Firebase项目相同?如果是这种情况,并且您尚未编辑google-services.json文件,您可以向Firebase提交支持票据。