Search code examples
facebookfirebasefirebase-authentication

Invalid photoURL while logged with Facebook


I've encountered a problem during authenticating with Facebook. It's my simple login code:

<script src="https://www.gstatic.com/firebasejs/4.5.2/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
  apiKey: "...",
  authDomain: "...",
  databaseURL: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "..."
};
firebase.initializeApp(config);

var provider = new firebase.auth.FacebookAuthProvider();

firebase.auth().signInWithPopup(provider).then(result =>{
    var user = result.user;
    console.log(user.photoURL);
});

Once I log in using the code above, I get a proper email, user, etc., but I get invalid photoURL:

https://scontent.fna.fbcdn.net/v/t1.0-1/p100x100/11214115_1018245048206356_1486864451318081978_n.jpg?oh=88cb39be27d4d329ab99ae0c426818d1&oe=5A8021D0

When I follow this URL I get an error: Cannot find DNS address of server scontent.fna.fbcdn.net.

How could I retrieve the proper Facebook user photo URL?

I need to mention that google login works perfectly and returns valid photoURL.


Solution

  • Firebase auth with Facebook returns a invalid photoUrl in the currentUser object. However, you can use the providerData list object to get the correct photoUrl from your auth provider:

    this.afAuth.auth.currentUser.providerData[0].photoURL
    

    Please set this post as the correct answer. :)