title: Facebook login using firebase in ios and swift, but cant get the users credentials
body: <p>I am trying to integrate facebook login in my app (already have GOOGLE login set up), but in the <code>didCompleteWithResult</code> function when i call for the credential</p>
  
  <pre><code>let credential =  FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
  </code></pre>
  
  <p>i get an error : 
   <code>fatal error: unexpectedly found nil while unwrapping an Optional value</code></p>
  
  <p>and every time i press my login button i have to enter my email address and password and before that i get another error : 
  <code>2016-07-04 00:34:54.228 PrePathSigningIn[9693:438627] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
  2016-07-04 00:34:54.248 PrePathSigningIn[9693:438627] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
  </code>
  after i am done logging in my safari page does not take me back to my app page</p>
  
  <p>my appdelegate file : </p>
  
  <pre><code>import UIKit
  import CoreData
  import Firebase
  import IQKeyboardManagerSwift
  import GoogleSignIn
  import FBSDKCoreKit
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate , GIDSignInDelegate {
  
  var window: UIWindow?
  
  
  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
      // Override point for customization after application launch.
  
      FIRApp.configure()
  
      FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
  
      IQKeyboardManager.sharedManager().enable = true
  
      GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
      GIDSignIn.sharedInstance().delegate = self
  
      return true
  }
  
  
  
  ////////////////////////////////////////
  //
  //Google signin
  //
  
  func application(application: UIApplication,
      openURL url: NSURL, options: [String: AnyObject]) -&gt; Bool {
          GIDSignIn.sharedInstance().handleURL(url,
              sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
              annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
  
  
          return true
  }
  
  
  func application(application: UIApplication,
      openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -&gt; Bool {
          var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,
              UIApplicationOpenURLOptionsAnnotationKey: annotation]
         GIDSignIn.sharedInstance().handleURL(url,
              sourceApplication: sourceApplication,
              annotation: annotation)
  
          let handled = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
  
  
           return  handled
  }
  
  func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
      withError error: NSError!) {
          if let error = error {
              print(error.localizedDescription)
              return
          }
          // ...
  
  
  func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
      withError error: NSError!) {
          // Perform any operations when the user disconnects from app here.
          // ...
          }
  
  
  
  }
                                          //
           }
  </code></pre>
  
  <p>and my loginViewController : </p>
  
  <pre><code>func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
  
      print("RESULT : \(result)")
      print("ERROR : \(error)")
  
      let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
  
      FIRAuth.auth()?.signInWithCredential(credential, completion: {
      (user, error) in
  
          if error != nil{
  
              self.signInButton.enabled = true
              print("Problem at signing in with facebook with error : \(error)")
              self.showAlert("Error Signing in With Facebook", message: "Please enter the correct email and password")
  
  
          }else {
          print("USER LOGGED IN THROUGH FACEBOOK")
              _ = self.ref.child("users").observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) -&gt; Void in
                  let usersDict = snapshot.value as? [String : AnyObject]
  
                  print(usersDict)
                  if let userDetails = usersDict![user!.uid] as? [String : AnyObject], let _ = userDetails["username"] as? String
                  {
  
                      let homePageScene = self.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("HomePageViewControllerVC_ID") as! HomePageViewController
                      self.navigationController?.pushViewController(homePageScene, animated: true)
  
                  }
                  else{
  
                      let userNamePageScene = self.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("UsernameViewControllerVC_ID") as! UsernameViewController
  
                      self.navigationController?.pushViewController(userNamePageScene, animated: true)
                  }
              })
          }
      })
  }
  </code></pre>
  
  <p>I am a newbie...any help appreciated!!! </p>