I am trying to utilize the login function, and when I switched to swift 4 I am now getting an error. the function crashes and gives a fatal error: unexpectedly found nil while unwrapping an Optional value
error. However, when I run the print statements for the email and password passed it prints them out fine as non-optional strings.
Below is my code:
@IBAction func Login(sender: AnyObject) {
let email = self._Email.text!
let password = self._Password.text!
print("below is the email")
print(email)
print("below is the password")
print(password)
FIRAuth.auth()!.signIn(withEmail: email, password: password, completion: { user, error in
if error == nil {
//successfull login
print("Successful login****************************************")
//performs a segue to the next view controller
if user!.isEmailVerified{
//if the email is verified
let vc = self.storyboard!.instantiateViewController(withIdentifier: "ProfileView") as! ProfileView
self.present(vc, animated: true, completion: nil)
}
else {
if let errCode = FIRAuthErrorCode(rawValue: error!._code) {
switch errCode {
case .errorCodeNetworkError:
print("There has been a connection error")
case .errorCodeInvalidEmail:
print("invalid email")
case .errorCodeEmailAlreadyInUse:
print("in use")
default:
print("Create User Error: \(error!)")
//error with login
self.signupErrorAlert(title: "Error", message: "Email or password is not recognized")
print ("Login Error**************")
}
}
}
}
})
}
The exception happens on the following line: FIRAuth.auth()!.signIn(withEmail: email, password: password, completion: { user, error in