0
votes

I have a little problem with angularfire/ionic/cordova app and most specially with facebook auth, I have push the code of my service . (I call my service function Auth.login in my Auth controller but it's this part of code who don't run) This code run perfectly whith ionic --serve. But impossible to access to faceboook login on an emulator or my device(iphone). When i click on " LOG IN WITH FB " i have nothing. I don't understand how i can resolve this probleme. Can you help me ?

app.factory("Auth", function($ionicModal, Findcity, $firebaseAuth,$localStorage, FirebaseUser, geoLocation ){

var provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday');
provider.addScope('user_location');
provider.addScope('email');
provider.addScope('user_photos');
provider.addScope('public_profile');
provider.addScope('user_about_me');


var Auth = {

login: function() {
  return $firebaseAuth().$signInWithPopup(provider)
    .then(function(result) {
      $localStorage.fbAccessToken = result.credential.accessToken;
      var facebookUser = firebaseAuth$().$getAuth().providerData[0];
      return FirebaseUser.get(facebookUser.uid)
      .then(function(user){
        console.log(facebookUser);
        if(user.$value == null) {
          console.log(user);
        FirebaseUser.save(facebookUser);
        }else {
         var lat = geoLocation.getGeolocation().lat;
         var lng = geoLocation.getGeolocation().lng;
         Findcity.city(lat, lng).then(function(city){
          var city_user = city;
          return firebase.database().ref('/users/' + facebookUser.uid).child('location').update({lat: lat, long: lng, city: city_user})
        })
      }
    })
  });
},
  return Auth;
});
1

1 Answers

0
votes

Firebase 3.x signInWithPopup/Redirect is not currently supported in a Cordova environment. Until this is supported (work in progress), you can use other plugins to get the OAuth response for Facebook, Google and then use signInWithCredential instead. You can use something like https://www.npmjs.com/package/cordova-plugin-facebook to get the Facebook access token and then sign in via auth.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken));