2016-12-25 58 views
0

我試圖用離子只是使用這個火力點身份驗證:使用Ionic2與火力權威性

signInWithFacebook(): firebase.Promise<FirebaseAuthState> { 
    if (this.platform.is('cordova')) { 
     console.log("trying to log in using cordova..."); 
     Facebook.login(['email', 'public_profile']).then(res => { 
     console.log("Logged in. result here"); 
     const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken); 
     console.log(firebase.auth().signInWithCredential(facebookCredential)); 
     return firebase.auth().signInWithCredential(facebookCredential); 
     }); 
    } else { 
     return this.auth$.login({ 
     provider: AuthProviders.Facebook, 
     method: AuthMethods.Popup 
     }); 
    } 
    } 

這段代碼在網絡的偉大工程,但在安卓(科爾多瓦)不起作用。

我調試爲什麼登錄按鈕不工作,我發現這樣的錯誤:

EXCEPTION: Error in ./HomePage class HomePage - inline template:6:0 caused by: Cannot read property 'then' of undefined....

Logged in. result here

EXCEPTION: Uncaught (in promise): ReferenceError: firebase is not defined ReferenceError: firebase is not defined at file:///android_asset/www/build/main.js:42039:42 at t.invoke...

關於第二個問題(沒有定義火力),我試圖

`import firebase from 'firebase';` 

但離子2編譯返回錯誤。

我只是使用的代碼使用離子2.

任何人有任何想法,爲什麼這可能發生的Angularfire2權威性?

回答

0

您沒有返回Facebook.login()。所以我相信當你嘗試在你的組件中訪問它時它會返回錯誤。

return Facebook.login(['email', 'public_profile']).then(res => { 
+0

它解決了問題,但返回了錯誤的數據。我需要返回這個:'firebase.auth()。signInWithCredential(facebookCredential)' – TheUnreal

+0

if firebase.auth()。signInWithCredential(facebookCredential);''返回一個承諾信息你需要的,你會收到在''signInWithFacebook()''中返回的承諾 – raj