2

I've been pulling my hair over this for quite a while now.

I'm trying to use Facebook Auth for Firebase. I have also initialized my app in app.module.ts But when I run the below-mentioned code on my Android device, I get

"RefrenceError: firebase is not defined"

  signInWithFacebook(){
    var _authInfo

Facebook.login(['email'])
  .then((_response) => {
    console.log(_response)

    _authInfo = _response

    return this._FBUserProfile();

  }).then((success) => {
    this.TEST = "IM IN";
    let creds = (firebase.auth.FacebookAuthProvider as any).credential(_authInfo.authResponse.accessToken)
    let providerConfig = {
      provider: AuthProviders.Facebook,
      method: AuthMethods.OAuthToken,
      remember: 'default',
      scope: ['email'],
    };
    this.af.auth.login(creds, providerConfig)
      .then((success) => {
        console.log("Firebase success: " + JSON.stringify(success));
        this. Error += (JSON.stringify(success));
        this.UID =  success.auth.uid;
      })
      .catch((error) => {
        console.log("Firebase failure: " + JSON.stringify(error));
        this. Error += (JSON.stringify(error))
      });

  })
  .catch((_error) => { this. Error +=(_error)  }) //Error caught here.


}



 _FBUserProfile() {

  return new Promise((resolve, reject) => {
    Facebook.api('me?fields=id,name,email,first_name,last_name,picture.width(100).height(100).as(picture_small),picture.width(720).height(720).as(picture_large)', [])
      .then((profileData) => {
        console.log(JSON.stringify(profileData));
        return resolve(profileData);
      }, (err) => {
        console.log(JSON.stringify(err));
        return reject(err);
      });
  });
}

And these are my imports.

import { Injectable } from '@angular/core';
import { AuthProviders, AngularFireAuth, FirebaseAuthState, AuthMethods, AngularFire } from 'angularfire2';
import { Platform } from 'ionic-angular';
import { Facebook } from 'ionic-native';

Also, note that I have run npm install firebase angularfire2 --save in the project folder

1 Answer 1

2

You are using this:

firebase.auth.FacebookAuthProvider

but you are not importing firebase, even you import angularfire you need import firebase if you use it like you are using.

So try adding this:

import * as firebase from 'firebase';

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.