@H_403_3@
@H_403_3@
在我的应用程序中,我使用电话身份验证登录并存储用户登录的用户电话号码和数据库中的uid.当使用现有用户电话号码登录时,它会创建具有相同uid和电话号码的新文档ID,您可以查看图像1和3.@H_403_3@
这是我用于登录的代码,如果用户存在则意味着它应该检查并导航到主控制器,否则签署用户详细控制器.@H_403_3@
@IBAction func loginbtn(_ sender: UIButton) { let defaults = UserDefaults.standard let credential: PhoneAuthCredential = PhoneAuthProvider.provider().credential(withVerificationID: defaults.string(forKey: "authVID")!,verificationCode: otpText.text!) Auth.auth().signIn(with: credential) { (user,error) in if error != nil { print("error: \(String(describing: error?.localizedDescription))") } else if user != nil { print("Phone number: \(String(describing: user?.phoneNumber))") let userInfo = user?.providerData[0] print("Provider ID: \(String(describing: userInfo?.providerID))") let currentUser = Auth.auth().currentUser?.uid var ref: DocumentReference? = nil ref = self.db.collection("Users").addDocument(data: [ "phoneNumber" : user?.phoneNumber as Any,"UID" : user?.uid as Any ]) { err in if let err = err { print("Error adding document: \(err)") } else { print("Document added with ID: \(ref!.documentID)") } } let storyboard = UIStoryboard(name: "Main",bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "HomeViewController") self.present(controller,animated: true,completion: nil) } else { } } }