Search code examples
swiftfirebase-authenticationfacebook-authentication

Swift Facebook Login sdk error with code 2


I am getting an error while logging in with Facebook. And it was working about 3-4 months ago.

Now I am back at developing this app again and I changed the development target to iOS 13.0 from iOS 12.0 and add the SceneDelegate and other necessary things. Actually, I don't think this is the reason but good to mention.

Now I am getting this error:

FBSDKLog: Cannot login without a valid login configuration. Please make sure the LoginConfiguration provided is non-nil Error Domain=com.facebook.sdk.core Code=2 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Cannot login without a valid login configuration. Please make sure the LoginConfiguration provided is non-nil}

while running this:

fbLoginManager.logIn(permissions: ["email, public_profile"], from: self) { (loginResult, error) in
        if error != nil {
            print(error!)
        }
        
        if let currentToken = AccessToken.current {
            let credential = FacebookAuthProvider.credential(withAccessToken: currentToken.tokenString)
            Auth.auth().signIn(with: credential) { (authResult, error) in
                if let error = error {
                    let authError = error as NSError
                    print(authError)
                } else {
                    DispatchQueue.main.async {
                        self.setupTabbar()
                        self.dismiss(animated: true, completion: nil)
                    }
                }
            }
        }
    }

I checked info.plist several times and apply the instructions from scratch but I am still getting this error.

I am using XCode 12.5 and Swift 5

Edit: When I remove the permissions it works but I actually need those permissions.


Solution

  • Solution

    I changed permissions from ["email, public_profile"] to: ["email", "public_profile"]

    so it looks like this:

    fbLoginManager.logIn(permissions: ["email", "public_profile"], from: self) { (loginResult, error) in
            if error != nil {
                print(error!)
            }
            
            if let currentToken = AccessToken.current {
                let credential = FacebookAuthProvider.credential(withAccessToken: currentToken.tokenString)
                Auth.auth().signIn(with: credential) { (authResult, error) in
                    if let error = error as NSError? {
                        print(error)
                    } else {
                        DispatchQueue.main.async {
                            self.setupTabbar()
                            self.dismiss(animated: true, completion: nil)
                        }
                    }
                }
            }
        }