Sign in function not working..throwing error...Firebase and Xcode 9

221 views Asked by At

I'm following along in a tutorial on youtube about how to create the user login and registration. I've created three view controllers... SignInVC, SignOutVC, and SignUpVC.

The sign up functionality works perfectly within the simulator...however, when I try to do the sign in portion, it does not work at all. It does not throw any type of error...I just click the sign in button and nothing.

Note: I didn't see the connection in the connections inspector like I did with the sign up view...so I tried dragging the outlet over again (control and drag button to the SignInVC) and now I see the connection in the connection inspector but I get this error now.....

Reading from private effective user settings. fatal error: unexpectedly found nil while unwrapping an Optional value 2017-09-04 14:50:03.988918-0400 Sample Project[12480:1387954] fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

Here is my code for the sign in vc:

import UIKit
import Firebase

class SignInVC: UIViewController {

//outlets

    @IBOutlet weak var emailTF: UITextField!
    @IBOutlet weak var passwordTF: UITextField!

//action


    @IBAction func onSignInTapped(_ sender: Any) {

        guard let email = emailTF.text,
        email != "",
        let password = passwordTF.text,
        password != ""
        else {
            AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all required fields")
            return
        }

        Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
            guard error == nil else{
                AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
                return
            }
            guard let user = user else { return }
            print(user.email ?? "MISSING EMAIL")
            print(user.displayName ?? "MISSING DISPLAY NAME")
            print(user.uid)

            self.performSegue(withIdentifier: "signInSegue", sender: nil)


        })

    }



}

As mentioned earlier, my signup works perfectly. here is the code for that...if it helps..

import UIKit
import Firebase

class SignUpVC: UIViewController {

    //outlets

    @IBOutlet weak var usernameTF: UITextField!

    @IBOutlet weak var emailTF: UITextField!

    @IBOutlet weak var passwordTF: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    //actions


    @IBAction func onSignUpTapped(_ sender: Any) {

        guard let username = usernameTF.text,
            username != "",
            let email = emailTF.text,
            email != "",
            let password = passwordTF.text,
            password != ""
            else {
                AlertController.showAlert(self, title: "Missing Info", message: "Please fill out all fields")
                return

        }

        Auth.auth().createUser(withEmail: email, password: password, completion:  { (user, error) in

            guard error == nil else {
                AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
                return
            }
            guard let user = user else { return }
            print(user.email ?? "Missing Email")
            print(user.uid)

            let changeRequest = user.createProfileChangeRequest()
            changeRequest.displayName = username
            changeRequest.commitChanges(completion: { (error) in
                guard error == nil else {
                    AlertController.showAlert(self, title: "Error", message: error!.localizedDescription)
                    return
                }

                self.performSegue(withIdentifier: "signUpSegue", sender: nil)


            })

        })

    }


}
1

There are 1 answers

0
william anaya On

Try in capacitor.config set server: { iosScheme: "ionic" }