用户使用Android的Firebase电话自动身份验证登录后,身份验证状态永远不会更改事件。
在非Android设备上的行为符合预期
async signinWithPhone(phoneNumber){
const loading = await this.loadingCtrl.create({
keyboardClose: false,
animated: true,
spinner: 'lines',
backdropDismiss: false,
})
await loading.present()
this.auth.verifyPhoneNumber(phoneNumber, 120000).then(async verificationId => {
loading.dismiss()
const alert = await this.alertCtrl.create({
header: 'Verify phone number',
message: 'Please provide the SMS code you received on your phone.',
inputs: [
{
name: 'code',
type: 'tel',
placeholder: 'SMS Code'
},
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
}, {
text: 'Okay',
handler: (data) => {
loading.present()
this.auth.signInWithVerificationId(verificationId, data.code).then(async res => {
console.log(res);
this.toast.show('Signed in')
this.router.navigate(['home'])
})
}
}
]
});
await alert.present();
}).catch(async err => {
this.toast.show(err, 'danger')
console.log(err);
loading.dismiss()
})
}
这是用户状态可观察的订阅。
this.auth.onAuthStateChanged().subscribe(user => {
console.log(user)
if(user){
this.user.next(user)
this.router.navigate(['home', 'menu'])
} else{
this.user.next(null)
this.router.navigate(['login'])
}
})
我在网上找不到任何解决方案,我不太了解它的基本原理。 预先感谢。