0

I tried to use Ionic 2 with firebase auth using this:

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

This code works great in web, but doesn't work in Android (Cordova).

I debugged why the login button is not working and I found this errors:

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...

Regards the second issue (firebase is not defined) I tried to

`import firebase from 'firebase';`

but Ionic 2 build returned error.

I just used the code in the Angularfire2 auth using Ionic 2.

Anyone has any idea why it might happen?

1 Answer 1

0

You are not returning Facebook.login(). So I believe it returns error when you try to access it in your component.

  return Facebook.login(['email', 'public_profile']).then(res => {
2
  • It solve the issue, but returns the wrong data. I need to return this: firebase.auth().signInWithCredential(facebookCredential)
    – TheUnreal
    Dec 25, 2016 at 10:19
  • if firebase.auth().signInWithCredential(facebookCredential); returns a promise with the information you require, you would receive that in the returned promise in signInWithFacebook()
    – raj
    Dec 25, 2016 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.