2016-11-12 123 views
0

即時通訊與Firebase身份驗證和谷歌提供商一些麻煩。我試圖用谷歌提供商登錄(這工作正常),但然後我想重定向到我的主頁,但即時通訊出錯了。Ionic 2谷歌登錄與火力點

我有一個身份驗證提供者:

import { Injectable } from '@angular/core'; 
import firebase from 'firebase'; 


@Injectable() 
export class AuthData { 
    // Here we declare the variables we'll be using. 
    public fireAuth: any; 
    googleProvider: any; 

    constructor() { 
    this.fireAuth = firebase.auth(); // We are creating an auth reference. 

    // Google Provider for Google Auth 
    this.googleProvider = new firebase.auth.GoogleAuthProvider(); 
    } 

    /** 
    * This function doesn't take any params, it just logs the current user out of the app. 
    */ 
    logoutUser(): any { 
    return this.fireAuth.signOut(); 
    } 

    /** 
    * This function doesn't take any params, it just signin the current user 
    * using google provider. 
    */ 
    googleSignin(): any { 
    return this.fireAuth.signInWithRedirect(this.googleProvider); 
    } 
} 

這是我app.component:

[all imports here] 

@Component({ 
    templateUrl: 'app.html' 
}) 
export class MyApp { 
    @ViewChild(Nav) nav: Nav; 

    rootPage: any = Home; 
    constructor(public platform: Platform) { 
    this.initializeApp(); 
    } 

    initializeApp() { 
    firebase.initializeApp(FirebaseConfig); 

    firebase.auth().onAuthStateChanged((user) => { 
     if (!user) { 
     this.nav.setRoot(Home); 
     } else { 
     this.nav.setRoot(Menu); 
     } 
    }); 

    this.platform.ready().then(() => { 
     StatusBar.styleDefault(); 
    }); 
    } 
} 

這是我home.ts:

[some imports here] 

@Component({ 
    templateUrl: 'home.html', 
}) 
export class Home { 

    constructor(public navCtrl: NavController, public authData: AuthData) {} 

    registerUserWithGoogle() { 
    this.authData.googleSignin(); 
    } 
} 

所以,當我嘗試從home.html(它對app.html的看法)與Google登錄到menu.html我有一些奇怪的行爲。我有一些截圖。

app.html:

<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav> 

home.html的:

<ion-content class="home"> 
    <div class="logo"> 
    <div class="logo-icon"> 
     <img src="assets/img/logotipo.png" alt=""> 
    </div> 
    </div> 
    <button ion-button block color="danger" class="google-btn" (click)="registerUserWithGoogle()"> 
    Log In with Google 
    </button> 
</ion-content> 

這是我所得到的,當我登錄:

pic1

如果我點擊箭頭我得到這個:

pic2

但現在我不能點擊sidemenu,我不知道它是否嵌套兩個離子視圖或其他東西。

謝謝

+1

signInWithRedirect和signInWithPopup尚未在離子/科爾多瓦環境中受支持。您必須使用Cordova插件才能登錄Google OAuth令牌並使用firebase.auth()。signInWithCredential(firebase.auth.GoogleAccessProvider.credential(null,googleAccessToken))以使用該憑證進行登錄。 – bojeil

+0

奧奇謝謝你生病嘗試儘快 –

+0

嗨我試試這個https://javebratt.com/firebase-3-email-auth/電子郵件和密碼驗證,而不是谷歌身份驗證,它也一樣,所以它可能是應用程序的原因?也許嵌套意見問題? –

回答

0

我讀了評論,所以這是現在2部分的問題:

1)對於谷歌驗證,該signInWithRedirect()signInWithPopUp()方法不科爾多瓦/離子應用工作尚未

你需要使用谷歌原生的插件來獲得登錄憑據,然後你可以將它們傳遞到firebase.auth.signInWithCredentials()

2)關於錯誤發送您的主頁:

有一個奇怪的錯誤在離子的navCtrl未推網頁它在用戶返回後:

firebase.auth().onAuthStateChanged((user) => { 
    if (!user) { 
    this.nav.setRoot(Home); 
    } else { 
    this.nav.setRoot(Menu); 
    } 
}); 

我得到了通過簡單的聲明rootPage: any = Menu;,然後做這個,而不是工作:

firebase.auth().onAuthStateChanged((user) => { 
    if (!user) { 
    this.nav.setRoot(Home); 
    } 
});