1
votes

I am connecting my application with Facebook and Google Firebase. I followed all steps and every thing working fine but the database generated in Firebase Google is empty. Do I need to use Realtime database and then store the FB user data programmatically? or FB user info is stored automatically in Firebase database, when you loggedIn. For reference: https://firebase.google.com/docs/auth/ios/facebook-login

-(void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error
{

    if (error == nil) {

        FIRAuthCredential *credential = [FIRFacebookAuthProvider
                                         credentialWithAccessToken:[FBSDKAccessToken currentAccessToken]
                                         .tokenString];

        [[FIRAuth auth] signInWithCredential:credential
                                  completion:^(FIRUser *user, NSError *error) {
                                      // ...
                                  }];
    } else {

        NSLog(@"%@", error.localizedDescription);
    }

}
- (IBAction)FBLogin:(id)sender {

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

    [login
     logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends",@"user_birthday",@"user_location"]
     fromViewController:self

     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if (error) {
             NSLog(@"Process error");
         } else if (result.isCancelled) {
             NSLog(@"Cancelled");
         } else {
             NSLog(@"Logged in");
             [self performSegueWithIdentifier:@"GotoMainMenu" sender:self];
         }
     }];
}
1
Signing in with Firebase Authentication does not automatically add information about the user to the Firebase Database. If you want to store such information, you'll have to do so yourself from your code. - Frank van Puffelen
Thanks @FrankvanPuffelen. - WasimSafdar

1 Answers

1
votes

...sorry I just edited this as I realized you are not using JavaScript. I'll leave the answer though as it might still help.

Wait until you get to password based authentication. That's where the real fun begins! :-)

The thing about Facebook is they don't give you the users email by default. I believe you can request access to it though via their developers portal. Other providers do provide email.

In terms of storing displayName, photoURL, and/or email, you DO store those in the Auth system and that system will remember the data server side, ...for password accounts. oAuth accounts pull this data upon login so it does not go stale.

I have a working Web auth boilerplate that will give you a headstart. It is at https://github.com/rhroyston/firebase-auth.

Below is how to do a password based user in one pass.

  function registerPasswordUser(email,displayName,password,photoURL){
    var user = null;
    //NULLIFY EMPTY ARGUMENTS
    for (var i = 0; i < arguments.length; i++) {
      arguments[i] = arguments[i] ? arguments[i] : null;
    }
    auth.createUserWithEmailAndPassword(email, password)
    .then(function () {
      user = auth.currentUser;
      user.sendEmailVerification();
    })
    .then(function () {
      user.updateProfile({
        displayName: displayName,
        photoURL: photoURL
      });
    })
    .catch(function(error) {
      console.log(error.message,7000);
    });
    console.log('Validation link was sent to ' + email + '.');
  }