在我的登录页面上我有一个调用此功能的按钮
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(){
this.googleplus.login({
'webClientId' : '',
'offline' : true
})
.then((res)=>{
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);
})
}).catch((err)=>{
alert('Error:' + err);
return false;
});
}
当我点击按钮时,这是通过手机上的提示显示的:
googleauth其他
auth1
auth1 高于return true
,因此应调用if(this.auth.signInGoogle()){..}
内的内容,而调用else {..}
部分。
在 auth1 警报之前调用 googleauth else 警报是否有像我必须使用的等待功能?是在线程中运行的函数?怎么会发生这种情况?我怎么能解决它?
提前谢谢你们
修改
我的帐户显示在firebase身份验证页面中
整个 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(){
this.googleplus.login({
'webClientId' : '..',
'offline' : true
})
.then((res)=>{
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);
})
}).catch((err)=>{
alert('Error:' + err);
return false;
});
}
getcurrentUser(){
return firebase.auth().currentUser;
}
}
答案 0 :(得分:0)
export class LoginPage {
constructor(public navCtrl: NavController, public navParams: NavParams, public auth: AuthProvider, public gameStatus: GamestatusProvider) {
firebase.auth().onAuthStateChanged(firebaseUser => {
if(firebaseUser){
this.navCtrl.setRoot(HomePage);
}
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad LoginPage');
}
anonAuth(){
this.auth.signInAnonym();
}
googleAuth(){
this.auth.signInGoogle();
}
}

export class AuthProvider {
constructor(public googleplus: GooglePlus, public gameStatus: GamestatusProvider) {}
signInAnonym(){
firebase.auth().signInAnonymously();
}
signInGoogle(){
this.googleplus.login({
'webClientId' : webClientIdGooglePlusApi,
'offline' : true
})
.then((res)=>{
const firecreds = firebase.auth.GoogleAuthProvider.credential(res.idToken);
firebase.auth().signInWithCredential(firecreds).then((success)=>{
return true;
}).catch((err)=>{
alert('Firebase auth failed ' + err);
})
}).catch((err)=>{
alert('Error:' + err);
return false;
});
}
signOut(){
firebase.auth().signOut();
}
}

正在工作,但我仍然想知道为什么我的第一次尝试没有用?