0

I am implementing Facebook Login (have followed the Facebook Developer docs successfully) in combination with Firebase Auth.

Once a user registers (NOT signs in!), they are segued to a separate view controller. This view controller is not shown if the user simply signed in. I have set up the loginButton and it's delegate functions as suggested in the Firebase/Facebook docs:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
    if let error = error {
        print("deadBeef wVC_faceBookButton Delegate failed to login user via fb: \(error.localizedDescription)")
        return
    }

    let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
    Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
        if let error = error {
            print("deadBeef wVC_faceBookButton Delegate failed to make Firebase Link: \(error.localizedDescription)")
            return
        }
        // How do I check if user is a new user or a returning user?

    }
}

Is there a way for me to find out if the user that logged in/registered via the Facebook loginButton is a new user that has just registered and I can therefore perform the required segue, or is a returning user that has just logged in and hence NOT perform the segue?

pho_pho
  • 672
  • 11
  • 30
  • 1
    There's a `isNewUser` method for that purpose. See https://stackoverflow.com/a/48638676/209103 (for Android, but the same method exists on iOS). https://firebase.google.com/docs/reference/swift/firebaseauth/api/reference/Classes/AdditionalUserInfo#isnewuser – Frank van Puffelen Oct 01 '18 at 23:29
  • Thanks @FrankvanPuffelen! Now that I have incorporated FB login into my app, do i have to check if the user is logged in to my app through FB (`if FBSDKAccessToken.current() {}`) everywhere in my app where I check Firebase if a user is logged in? Or is it sufficient to only check Firebase? – pho_pho Oct 02 '18 at 10:41

0 Answers0