0

여기 거래가 있습니다. 지금 나는 사용자가 가입 할 수있는 viewcontroller를 가지고 있으며, 작동 중입니다 (Firebase 콘솔에서 확인). 다음 단계는 두 개의 필드와 로그인 버튼이있는 다른보기가 있다는 것입니다. 로그인 버튼은 세 번째보기 인 홈에 대한 세그멘트를 갖습니다. 그러나 두 텍스트 필드에 아무 것도 입력되지 않은 경우에도이를 클릭 할 수 있습니다. 사용자가 가입보기에서 만든 세부 정보를 입력하여 로그인하는 경우에만 버튼이 작동하므로 로그인해야합니다.Firebase 로그인 시스템

어떻게하면됩니까? 문 당신이 로그인이 일을 보여 필드를 지 웁니다 볼 경우

@IBAction func loginAction(sender: AnyObject) 
{ 
    if self.emailField.text == "" || self.passwordField.text == "" 
    { 
     let alertController = UIAlertController(title: "Oops!", message: "Please enter an email and password.", preferredStyle: .Alert) 

     let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil) 
     alertController.addAction(defaultAction) 

     self.presentViewController(alertController, animated: true, completion: nil) 
    } 
    else 
    { 
     FIRAuth.auth()?.signInWithEmail(self.emailField.text!, password: self.passwordField.text!) { (user, error) in 

      if error == nil 
      { 
       self.emailField.text = "" 
       self.passwordField.text = "" 
      } 
      else 
      { 
       let alertController = UIAlertController(title: "Oops!", message: error?.localizedDescription, preferredStyle: .Alert) 

       let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil) 
       alertController.addAction(defaultAction) 

       self.presentViewController(alertController, animated: true, completion: nil) 
      } 

두 번째에서 : 이미 로그인 코드가 있습니다.

필자가 필요한 것은 Firebase 데이터베이스에 정확한 세부 정보가 입력되어있는 경우에만 로그인 할 수 있다는 것입니다.

답변

0

오류가 없는지 확인하는 대신 데이터가 이처럼 사용자 개체인지 확인하십시오.

FIRAuth.auth()?.signInWithEmail(self.emailField.text!, password: self.passwordField.text!) { (user, error) in 

     if user != nil 
     { 

     let VC = storyboard?.instantiateViewControllerWithIdentifier("Identifier") as! AccountViewController //The file that controls the view 

     self.presentViewController(VC, animated: true, completion: nil) 

     } 
     else 
     { 
      let alertController = UIAlertController(title: "Oops!", message: error?.localizedDescription, preferredStyle: .Alert) 

      let defaultAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil) 
      alertController.addAction(defaultAction) 

      self.presentViewController(alertController, animated: true, completion: nil) 
     } 
+0

방법이 다음보기로 이동 나를 도움이 되나요? – matthewdossantos

+0

오, 질문을 잘못 읽었습니다. – Eli

+0

http://imgur.com/a/vZlrz이 오류가 발생합니다. 너 나 좀 도와 줄 수있어? :) – matthewdossantos

0

나는 스스로를 추가하여 문제를 해결할 수있었습니다. 따라서 생성

storyboard?.instantiate. 

의 뿅는 :

self.storyboard?instantiate.