简体   繁体   English

使用文本字段数据创建 Firestore 文档

[英]Creating Firestore document with text field data

So im making a sign up page on xcode with firebase and it currently work well but I would like to get more information from the user such as the first name and the last name.所以我用 firebase 在 xcode 上创建了一个注册页面,它目前运行良好,但我想从用户那里获得更多信息,例如名字和姓氏。 Basically I want my code to automatically create a document named with the email of the user that just sign up in the "Users" collection on firestore and after create the field "FirstName" and "LastName" with the text in those textfield.基本上,我希望我的代码自动创建一个名为 email 的文档,该用户刚刚在 firestore 的“Users”集合中注册,并在使用这些文本字段中的文本创建字段“FirstName”和“LastName”之后。 You can see my code below.你可以在下面看到我的代码。 Thanks for your help in advance.提前感谢您的帮助。 And I also provide a screenshot ( I did it manually to explain what I want it to do )而且我还提供了一个屏幕截图(我手动完成以解释我想要它做什么)

@IBOutlet weak var FirstName: UITextField!
@IBOutlet weak var LastName: UITextField!
@IBOutlet weak var Email: UITextField!
@IBOutlet weak var Password: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

@IBAction func SignUpButton(_ sender: Any) {
    if Email.text?.isEmpty == true {
        print("No text in email field")
        return
    }
    if Password.text?.isEmpty == true {
        print("No text in password field")
        return
    }
    if FirstName.text?.isEmpty == true {
        print("No text in first name field")
        return
    }
    if LastName.text?.isEmpty == true {
        print("No text in Last name field")
        return

    }
    SignUp()
}

@IBAction func LoginButton(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(identifier: "SignInPage")
    vc.modalPresentationStyle = .overFullScreen
    present(vc, animated: true)
}

func SignUp() {

    Auth.auth().createUser(withEmail: Email.text!, password: Password.text!) { (authResult, error) in
        guard let user = authResult?.user, error == nil else {
            print("Error \(error!.localizedDescription)")
        return
        }

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(identifier: "Manager0")
           vc.modalPresentationStyle = .overFullScreen
        self.present(vc, animated: true)

    }
}

在此处输入图像描述

You cannot get a user's first and last name as Firebase only honours the full name only via displayName .您无法获取用户的名字和姓氏,因为 Firebase 仅通过displayName尊重全名。

Moreover, with email and password login, you only get the email - as Firebase would have no way to get the user's Name.此外,使用 email 和密码登录,您只能获得 email - 因为 Firebase 将无法获得用户名。 (Suppose a user has Yahoo Email ID - how would it get the name of the user?) (假设用户拥有 Yahoo Email ID - 它如何获取用户名?)

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

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