繁体   English   中英

授权用户使用Firebase无效

[英]Authorizing user to firebase doesn’t work

我正在创建一个基本的注册和登录页面应用程序,当用户成功注册或登录后,它将进入主屏幕。这是我的代码:

这是我所谓的按钮按下功能

signupButton.addTarget(self, action: #selector(signupButtonPressed), for: .touchUpInside)

这是创建用户并存储在数据库中的代码。

@objc func signupButtonPressed() {
    // Check that the text fields aren't empty
    if let username = username.text, let password = password.text, let email = email.text, let country = countryTextField.text {
        // Create a user
        func createUser(withEmail email: String, username: String, password: String, country: String) {

            // Sign up user only if all the text fields are filled
            Auth.auth() .createUser(withEmail: email, password: password) { (result, error) in

                if result != nil {

                    // User found, go to main page
                    let mainPage = MainScreen()
                    self.present(mainPage, animated: true, completion: nil)

                } else {

                    // Error: show error message
                    print("Failed to sign user up with error: ", error!.localizedDescription)
                    return
                }

                guard let userID = result?.user.uid else {return}

                let values = ["email": email, "username": username]

                Database.database().reference().child("Users").child(userID).updateChildValues(values, withCompletionBlock: {(error, ref) in
                    if let error = error {
                        print("Failed to update database values with error: ", error.localizedDescription)
                        return}})
            } 
        }
    }
}

问题是,当我按下按钮时,没有任何效果。 希望有人可以帮助我,谢谢!

@objc func signupButtonPressed() {
    if let username = username.text, let password = password.text, let email = email.text, let country = countryTextField.text {
       createUser(withEmail: email, username: username, password: password, country: country)
    }
}


func createUser(withEmail email: String, username: String, password: String, country: String) {
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM