I have a simple button action
I do verify the email and password before going into this, but this is my Firebase code. When you click on the button, it will get into the VerifyUserInformation
function and the response will spit out. Basically, the segue's in VerifyUserInformation
will not run for me, the dismiss function doesn't dismiss the modal (present full screen) either.
What can be done to fix this?
Auth.auth().signIn(withEmail: emailOutlet.text!, password: passwordOutlet.text!) { [weak self] user, error in
guard let strongSelf = self else { return }
if let error = error {
self!.displaySnackbar(messageString: "\(error.localizedDescription)")
return
}
self!.preferences.setValue(true, forKey:SHARED_PREF_USER_LOGGED_IN_KEY)
var firstTimeUser = self!.preferences.bool(forKey:FIRST_TIME_USER)
print("\(self!.TAG) FirstTimeUser: \(firstTimeUser)")
if (firstTimeUser) {
print("\(self!.TAG) This is the first time the user is using the application.")
self?.VerifyUserInformation(firebaseId: "\(Auth.auth().currentUser!.uid)")
} else {
print("\(self!.TAG) User can head into the Application.")
self!.performSegue(withIdentifier: "MainScreen", sender: nil)
self?.progressBar.isHidden = true
self!.loginButtonOutlet.isHidden = false
}
}
To verify the user, I run this function.
func VerifyUserInformation(firebaseId: String) {
let urlString = ADD_USER_FOR_ACCOUNT
let param = [
FROM_APP: "true",
USER_FIREBASE_ID: firebaseId,
GET_USER_ACCOUNT_INFORMATION: "true"
] as [String : Any]
AF.request(urlString, method: .post, parameters: param ,encoding: URLEncoding.default).responseJSON {
response in
switch response.result {
case .success:
print("\(self.TAG)\n***Response***\n\(response)\n***END***")
if let result = response.value {
let JSON = result as! NSDictionary
let errorResponse = JSON["error"] as! Int
if (errorResponse == 1) {
print("\(self.TAG) Error verifying the user.")
self.displaySnackbar(messageString: "Error verifying user. Try again.")
} else {
print("\(self.TAG) User is verified")
let messageResponse = JSON["message"] as! String
if (messageResponse == "user has items") {
print("\(self.TAG) User has items, go into MainScreen")
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.performSegue(withIdentifier: "MainScreen", sender: nil)
self.dismiss(animated: false, completion: nil)
self.preferences.setValue(false, forKey:FIRST_TIME_USER)
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
}
}
} else {
print("\(self.TAG) User has 0 items, go into Second Onboarding")
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.performSegue(withIdentifier: "SecondOnBoarding", sender: nil)
self.dismiss(animated: false, completion: nil)
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
}
}
}
}
}
break
case .failure(let error):
self.loginButtonOutlet.isHidden = false
self.progressBar.isHidden = true
self.displaySnackbar(messageString: "Error getting user information. Try again.")
print("\(self.TAG) \(error)")
}
}
}
After removing the dismiss()
, it started to work.