2017-07-10 4 views
1

auf der Anmeldungsseite Ich habe eine Schaltfläche bekommt, die diese Funktion(Firebase | Ionic) GoogleAuth verzögerte Reaktion falsch Rückkehr vor fertig?

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"); 
 
    } 
 
    }

in meinem Auth-Provider ruft dies ist die signInGoogle() Funktion

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 
 
    }
Diese

ist was angezeigt v ia Alarm auf meinem Handy, wenn ich auf den Button klicken:
googleauth sonst
auth1

auth1 ist über return true, so dass das Material innerhalb if(this.auth.signInGoogle()){..} sollte aufgerufen werden, sondern die else {..} Teil genannt wird.
die googleauth sonst alert wird vor der auth1 warnung alarm ist da so etwas wie eine wartende funktion die ich verwenden muss? laufen die Funktionen in Threads? Wie kann das passieren? Wie könnte ich es reparieren?

Danke Jungs im Voraus


bearbeiten
mein Konto in Feuerbasis Authentifizierungsseite
Die ganze 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; 
 
    } 
 

 
}
gezeigt

Antwort

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(){ 
 
    \t this.googleplus.login({ 
 
     'webClientId' : webClientIdGooglePlusApi, 
 
     'offline' : true 
 
    }) 
 
    \t .then((res)=>{ 
 
    \t \t const firecreds = firebase.auth.GoogleAuthProvider.credential(res.idToken); 
 
     firebase.auth().signInWithCredential(firecreds).then((success)=>{   
 
      return true; 
 
     }).catch((err)=>{ 
 
      alert('Firebase auth failed ' + err); 
 
     }) \t \t 
 
    \t }).catch((err)=>{ 
 
    \t \t alert('Error:' + err); 
 
     return false; 
 
    \t }); \t 
 
    } 
 

 
    signOut(){ 
 
    firebase.auth().signOut(); 
 
    } 
 
}

funktioniert, aber ich würde noch gerne wissen, warum didnt mein erster Versuch gearbeitet?