Today, let's learn how to sign in to Firebase using our previously logged in Facebook user.
First, we'll create a Firebase application at https://console.firebase.google.com.
Secondly, let's install the Firebase SDK using cocoapods and modifying our Podfile configuration.
Finally, we'll call the method in Swift that logs in our user into Firebase immediately after Facebook perform authentication.
!syntax-highlight
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
//...
func showEmailAddress() {
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else { return }
let credentials = FIRFacebookAuthProvider.credential(withAccessToken: accessTokenString)
FIRAuth.auth()?.signIn(with: credentials, completion: { (user, error) in
if error != nil {
print("Something went wrong with our FB user: ", error ?? "")
return
}
print("Successfully logged in with our user: ", user ?? "")
})
//...
}
}