title: Firebase 3.x - Facebook Login
body: <p>In<code>Firebase 2.5.1</code>, I used to do this, and it was working:</p>
  
  <pre><code>@IBAction func facebookLoginDidTouch(sender: AnyObject) {
  
     let facebookLogin = FBSDKLoginManager() 
  
    facebookLogin.logInWithReadPermissions(["public_profile", "email"], fromViewController: self, handler: {
      (facebookResult, facebookError) -&gt; Void in
          if facebookError != nil {
              print("Facebook login failed. Error \(facebookError)")
          } else if facebookResult.isCancelled {
              print("Facebook login was cancelled.")
          } else {
              let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
              myRootRef.authWithOAuthProvider("facebook", token: accessToken, withCompletionBlock: { error, authData in
  
                      if error != nil {
                          print("Login failed. \(error)")
                      } else {
                          print("Logged in!")
                          let newUser = [
                              "provider": user.provider,  
                              "imageUrl": user!.providerData["profileImageURL"] as String,    // etc
                          ]
                      }
               })
           }
     })
  }
  </code></pre>
  
  <p>Now I am trying to achieve this in <code>Firebase 3.x</code>. However, I got confused on where I should place permissions and stuff</p>
  
  <p>This is what I tried so far</p>
  
  <pre><code>@IBAction func facebookLoginDidTouch(sender: AnyObject) {
  
     let facebookLogin = FBSDKLoginManager()
  
     let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
  
     FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
      if error != nil {
          print("Login failed. \(error)")
      } else {
          print("Logged in!")
  
          let newUser = [
             "provider": user.provider,
             "imageUrl": user!.providerData["profileImageURL"] as String
          ]
      }
     })
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <pre><code> facebookLogin.logInWithReadPermissions(["public_profile", "email"], fromViewController: self, handler: {
      (facebookResult, facebookError) -&gt; Void in
      if facebookError != nil {
          print("Facebook login failed. Error \(facebookError)")
      } else if facebookResult.isCancelled {
          print("Facebook login was cancelled.")
      } else {
          // your firebase authentication stuff..
  
          let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
  
          FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
              if error != nil {
                  print("Login failed. \(error)")
              } else {
                  print("Logged in!")
  
                  let userID = Helpers.extractUID(user!)
  
                  let rootRef = FIRDatabase.database().reference()
                  let userRef = rootRef.child("users").child(userID)
  
                  userRef.observeEventType(.Value, withBlock: { snapshot in
                      if snapshot.value is NSNull {
                          let newUser = [
                              "providerId": user?.providerID,
                              "displayName": user?.displayName,
                          ]
                         userRef.setValue((newUser as! AnyObject))
                         // perform segue
                      }
                  })
               }
           })
  </code></pre>