想知道是否有人可以帮助我。我刚刚完成了我的注册页面,用户可以在其中创建一个帐户。我现在遇到的问题是,在登录视图中,用户只需按下“登录”按钮,即使他们的电子邮件和密码不正确,也会将其重定向到下一个视图。
class LoginViewController: UIViewController, GIDSignInUIDelegate {
@IBOutlet var userEmailLoginField: UITextField!
@IBOutlet var userPasswordLoginField: UITextField!
@IBAction func loginButton(_: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController
guard let email = userEmailLoginField.text, let password = userPasswordLoginField.text else { return }
FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
}
}
答案 0 :(得分:0)
尝试移动实例化新视图控制器的代码。在下面的示例中,我将其移动到仅在使用Firebase进行身份验证时没有错误时才会运行。
class LoginViewController: UIViewController, GIDSignInUIDelegate {
@IBOutlet var userEmailLoginField: UITextField!
@IBOutlet var userPasswordLoginField: UITextField!
@IBAction func loginButton(_: Any) {
guard let email = userEmailLoginField.text, let password = userPasswordLoginField.text else { return }
FIRAuth.auth()?.signIn(withEmail: email, password: password) { (user, error) in
if let error = error {
print(error.localizedDescription)
return
} else {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBarController
}
}
}