'Facebook login user data not displaying in firebase console

I have implemented email and Facebook login in my app using firebase. My code is as below:

For fb login :

FireBaseHelper.fireBaseHelper.BASE_REF.authWithOAuthProvider("facebook", token: "123") { (error, data) -> Void in

        APP_DELEGATE.hideActivityIndicator()
        if error != nil {
            print(error)
            self.loginErrorAlert("Oops!", message: "Check your username and password.")
        } else {

            // Be sure the correct uid is stored.

            NSUserDefaults.standardUserDefaults().setValue(data.uid, forKey: "uid")

            // Enter the app!

            self.performSegueWithIdentifier("CurrentlyLoggedIn", sender: nil)
        }
    }

For email signup :

     let username = usernameField.text
    let email = emailField.text
    let password = passwordField.text

    if username != "" && email != "" && password != "" {

        APP_DELEGATE.showActivityIndicator()

        FireBaseHelper.fireBaseHelper.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in



            if error != nil {
                 APP_DELEGATE.hideActivityIndicator()
                // There was a problem.
                self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Try again.")

            } else {

                // Create and Login the New User with authUser
                FireBaseHelper.fireBaseHelper.BASE_REF.authUser(email, password: password, withCompletionBlock: {
                    err, authData in

                    let user = ["provider": authData.provider!, "email": email!, "username": username!]

                      FireBaseHelper.fireBaseHelper.USER_REF.childByAppendingPath(authData.uid).setValue(user, withCompletionBlock: { (error, firebase) -> Void in

                        if error != nil {
                             APP_DELEGATE.hideActivityIndicator()
                            self.signupErrorAlert("Oops!", message: "Having some trouble creating your account. Try again.")

                        }else
                        {
                             APP_DELEGATE.hideActivityIndicator()
                            // Store the uid for future access - handy!
                            NSUserDefaults.standardUserDefaults().setValue(result ["uid"], forKey: "uid")

                            // Enter the app.
                            self.performSegueWithIdentifier("NewUserLoggedIn", sender: nil)

                        }
                      })
                })
           }
        })

    }else
    {
        signupErrorAlert("Oops!", message: "Don't forget to enter your email, password, and a username.")
    }

And helper class code:

class FireBaseHelper: NSObject {

    static let fireBaseHelper = FireBaseHelper()

    private var _BASE_REF = Firebase(url: "https://poc-demoApp.firebaseio.com")
    private var _USER_REF = Firebase(url: "https://poc-demoApp.firebaseio.com/users")
 var BASE_REF: Firebase {
        return _BASE_REF
    }

    var USER_REF: Firebase {
        return _USER_REF
    }

 var CURRENT_USER_REF: Firebase {
        let userID = NSUserDefaults.standardUserDefaults().valueForKey("uid") as! String

        let currentUser = Firebase(url: "\(BASE_REF)").childByAppendingPath("users").childByAppendingPath(userID)

        return currentUser!
    }
}

Problem is when i sign up with email user I can see that user data on dashboard of firebase and when i am sign up with fb , that user's data are not displaying on dashboard, let me know what is issue. Anything i miss? Its showing fb signup successfully



Solution 1:[1]

Firebase only stores a list of email+password users. It doesn't store any data for users of your app that are signed with social providers (such as Facebook). So there is nothing to show on the Firebase dashboard for those users.

If you want to store information about Facebook users in your database, see the section on storing user data.

Solution 2:[2]

I also had the same issue and @RenanSilveira is right. There are just some updates in the FBSDKLoginKit package needing "AccessToken.current!.tokenString" instead. This is what it looks like:

let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)

Auth.auth().signIn(with: credential) { (user, error) in
    if let error = error {
        print("Facebook authentication with Firebase error: ", error)
        return
    }
    print("User signed in!")
}

And this is the console after Facebook login Console after Facebook login.

Solution 3:[3]

I was facing the same problem and I found out that after a user successfully signs in with Facebook, you need to get an access token for the signed-in use, exchange it for a Firebase credential and finally authenticate with Firebase using the Firebase credential.

Here is an example (don't forget to import FBSDKLoginKit and FirebaseAuth libraries):

let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

Auth.auth().signIn(with: credential) { (user, error) in
      if let error = error {
        print("Facebook authentication with Firebase error: ", error)
        return
      }
      print("User signed in!") // After this line the Facebook login should appear on your Firebase console
    }

Here is a screen shot of the console after Facebook login:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen
Solution 2 Mr R
Solution 3 Renan Silveira