0

I have a few things I'm trying to accomplish. First, my email and password don't matter if they're filled or not to login. I would like the app to check if email and password is filled and correct before logging in. Secondly, I would like to put in a username when they register so it would show up on the profile page and tell other users who they're without revealing an email address. I'm using Firebase and I thought this would do the trick, but it doesn't. I looked over this Stack overFlow Post and have everything correct I think, but its still letting you login without credentials.

@IBAction func loginRegisterBtnPressed(_ sender: AnyObject) {
    performSegue(withIdentifier: "profileVC", sender: self)
    if let email = emailTextField.text, let password = passwordTextField.text {
        FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error ) in
            if error == nil {
                print("DAW: User Created")
            } else {
               FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error ) in
            if error != nil {
                    print ("DAW: User failed to authenticate with Firebase")
            } else {
                    print ("DAW: Successfully")
                if let user = user {
                    self.completeSignIn(id: user.uid)
                        }
                    }
               })
            }
        })
    }
}
Community
  • 1
  • 1
Darin Wilson
  • 169
  • 1
  • 2
  • 9

1 Answers1

0
@IBAction func loginRegisterBtnPressed(_ sender: AnyObject) {

    if let email = emailTextField.text, let password = passwordTextField.text {
        if email != "" && password != ""{
            FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error ) in
            if error == nil {
                performSegue(withIdentifier: "profileVC", sender: self)
            } else {
                FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error ) in
                    if error != nil {
                        print ("DAW: User failed to authenticate with Firebase")
                    } else {
                        print ("DAW: Successfully")
                        if let user = user {
                            self.completeSignIn(id: user.uid)
                        }
                    }
                })
            }
        })
       }
    }
}
Dravidian
  • 9,945
  • 3
  • 34
  • 74