swift – The right way to repair ‘Sorry, one thing went improper’ when making an attempt to log in with Fb on iOS utilizing Firebase?

0
176


Fb log in error:

“Sorry, one thing went improper.
We’re engaged on it and we’ll get it fastened as quickly as we will.”

import FirebaseAuth
import FacebookLogin

personal let facebookLoginButton: FBLoginButton = {
        let button = FBLoginButton()

        //button.permissions = ["email","public_profile"]
        button.permissions = ["public_profile", "email"]
        
        return button
    }()

override func viewDidLoad() {
        tremendous.viewDidLoad()

        facebookLoginButton.delegate = self
        

        
        // Add subviews
        view.addSubview(scrollView)
        scrollView.addSubview(imageView)
        scrollView.addSubview(emailField)
        scrollView.addSubview(passwordField)
        scrollView.addSubview(loginButton)
        scrollView.addSubview(facebookLoginButton)
    }

override func viewDidLayoutSubviews() {
        tremendous.viewDidLayoutSubviews()

        facebookLoginButton.body = CGRect(x: 30,
                                           y: loginButton.backside + 10,
                                           width: scrollView.width - 60,
                                           top: 52)
        facebookLoginButton.body.origin.y = loginButton.backside + 20
    }

{
    
    func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
        // no operation
    }
    
    func loginButton(_ loginButton: FBLoginButton, didCompleteWith outcome: LoginManagerLoginResult?, error: Error?) {
        
        guard let token = outcome?.token?.tokenString else {
            if let error = error {
                print("Consumer did not log in with fb: (error)")
            }
            return
        }
        
        let facebookRequest = FBSDKLoginKit.GraphRequest(graphPath: "me",
                                                         parameters: ["fields": "email, name"],
                                                         tokenString: token,
                                                         model: nil,
                                                         httpMethod: .get)
        
        
        
        facebookRequest.begin(completionHandler: { _, outcome, error in
            guard let outcome = outcome as? [String: Any], error == nil else {
                print("Didn't make fb graph request")
                return
            }
            
            guard let userName = outcome["name"] as? String,
                  let electronic mail = outcome["email"] as? String else {
                print("Didn't get electronic mail and identify from fb outcome")
                return
            }
            
            let nameComponents = userName.parts(separatedBy: " ")
            guard nameComponents.rely == 2 else {
                return
            }
            let firstName = nameComponents[0]
            let lastName = nameComponents[1]
            
            DatabaseManager.shared.userExists(with: electronic mail, completion: { exists in
                if !exists {
                    DatabaseManager.shared.insertUser(with: ChatAppUser(firstName: firstName,
                                                                        lastName: lastName,
                                                                        emailAddress: electronic mail))
                }
            })
            
            let credential = FacebookAuthProvider.credential(withAccessToken: token)
            
            FirebaseAuth.Auth.auth().signIn(with: credential, completion: { [weak self] authResult, error in
                guard let self = self else {return}
                
                guard authResult != nil, error == nil else {
                    if let error = error {
                        print("Fb credential login failed, MFA could also be wanted: (error)")
                    }
                    return
                }
                
                print("Efficiently logged person in")
                self.navigationController?.dismiss(animated: true, completion: nil)
            })
        })
        
        
    }
    
    
}