簡體   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