1
在我的登錄頁我有一個按鈕時調用這個函數(Firebase | Ionic)GoogleAuth在完成前延遲迴復錯誤返回?
googleauth(){
if(this.auth.signInGoogle()){
alert("1");
if(this.auth.getcurrentUser().displayName){
alert("2");
this.gameStatus.players[0].name = this.auth.getcurrentUser().displayName;
alert("3");
this.navCtrl.setRoot(HomePage);
}
}else{
alert("googleauth else");
}
}
在我的身份驗證提供者,這是signInGoogle()函數
signInGoogle(){
\t this.googleplus.login({
'webClientId' : '',
'offline' : true
})
\t .then((res)=>{
\t \t const firecreds = firebase.auth.GoogleAuthProvider.credential(res.idToken);
firebase.auth().signInWithCredential(firecreds).then((success)=>{
alert("auth1");
return true;
}).catch((err)=>{
alert('Firebase auth failed ' + err);
}) \t \t
\t }).catch((err)=>{
\t \t alert('Error:' + err);
return false;
\t }); \t
}
這是什麼顯示v我的手機上IA警報當我點擊該按鈕:
googleauth其他
auth1
auth1高於return true
,所以裏面if(this.auth.signInGoogle()){..}
的東西應該叫,而是在else {..}
部分被調用。
googleauth else提醒之前調用auth1提醒是否有像我需要使用的等待函數?函數在線程中運行?這怎麼會發生?我怎麼解決它?
謝謝你們提前
編輯
我的帳戶中火力認證頁面顯示
整個authProvider
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { GooglePlus } from '@ionic-native/google-plus';
import * as firebase from 'firebase/app';
import { GamestatusProvider } from '../../providers/gamestatus/gamestatus';
@Injectable()
export class AuthProvider {
constructor(public googleplus: GooglePlus) {}
signInGoogle(){
\t this.googleplus.login({
'webClientId' : '..',
'offline' : true
})
\t .then((res)=>{
\t \t const firecreds = firebase.auth.GoogleAuthProvider.credential(res.idToken);
firebase.auth().signInWithCredential(firecreds).then((success)=>{
alert("auth1");
return true;
}).catch((err)=>{
alert('Firebase auth failed ' + err);
}) \t \t
\t }).catch((err)=>{
\t \t alert('Error:' + err);
return false;
\t }); \t
}
getcurrentUser(){
\t return firebase.auth().currentUser;
}
}