Swift - login in VC, allows anyone to enter not verifying username and passwords match or saved

73 views Asked by At

With using firebase as well. My signup is working well and it registers users. But my login was working fine at start but now it allows anyone to go to the next view(login).

Here's my code:

SignInVC..

import UIKit
import Firebase

class SignInVC: UIViewController {
    @IBOutlet weak var emailTF: UITextField!
    @IBOutlet weak var passwordTF: UITextField!

    @IBAction func onSignInTapped(_ sender: Any) {
        guard let email = emailTF.text,
        email != "",
        let password = passwordTF.text,
        password != ""
            else {
               AlertController.showAlert(self, title: "Missing Information", message: "Please fill in username and password")
                return
        }

        Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
            guard error == nil
                else {
                    AlertController.showAlert(self, title: "Oops!", message: error!.localizedDescription)
                    return
            }
            guard let user = user else {return}
            print(user.email ?? "Missing email address")
            print(user.displayName ?? "Missing name")
            print(user.uid)

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

    //remove keyboard
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }    
}

AlerControllerVC

import UIKit
import Firebase

class AlertController {
    static func showAlert(_ inViewController: UIViewController, title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default, handler: nil)
        alert.addAction(action)
        inViewController.present(alert, animated: true, completion: nil)
    }
}

I tried many was and rewrote it again but wont work correct again, when executed it says:

".SignInVC: 0x7fd99c208280> whose view is not in the window hierarchy!"

1

There are 1 answers

0
ahmed On

Please check if your segue is from button to ViewController or from ViewController to ViewController. if it is from button to VC then it does not depend upon the code you wrote