hg5*_*g56 3 ios firebase swift
它在我的控制台中打印 CHANGED 但没有任何变化,用户电子邮件保持不变。占位符文本恢复为原始电子邮件,我的 Firebase 数据库用于该特定用户的电子邮件也未更改。我想让用户可以选择更改他们个人资料的任何部分,包括电子邮件、密码、位置和他们在首次注册时存储的其他值。为了做到这一点,我是否必须将他们注销并让他们重新登录?这似乎是一种糟糕的用户体验。
class SettingsViewController: UIViewController {
@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
@IBOutlet weak var location: UITextField!
@IBOutlet weak var updateEmail: UIButton!
@IBOutlet weak var updateLocation: UIButton!
@IBAction func updateEmailAction(_ sender: Any) {
let currentUser = Auth.auth().currentUser
currentUser?.updateEmail(to: email.text!) { error in
if let error = error {
print(error)
} else {
print("CHANGED")
}
}
}
var dataBaseRef: DatabaseReference! {
return Database.database().reference()
}
override func viewDidLoad() {
super.viewDidLoad()
let userRef = dataBaseRef.child("users/\(Auth.auth().currentUser!.uid)")
userRef.observe(.value, with: { (snapshot) in
let user = Users(snapshot: snapshot)
if let email = user.email{
self.email.placeholder = email
}
if let location = user.location{
self.location.placeholder = location
}
}
)}
Run Code Online (Sandbox Code Playgroud)
.updateEmail 函数更新用户Firebase 凭据中的电子邮件,与 /users 节点中存储的内容无关。
如果您在那里保留重复的电子邮件,则需要在 .updateEmail 函数成功时将该数据写入 /users/uid 节点。即 /users 节点是您创建的,不是由 Firebase 维护的。
@IBAction func updateEmailAction(_ sender: Any) {
let currentUser = Auth.auth().currentUser
currentUser?.updateEmail(to: email.text!) { error in
if let error = error {
print(error)
} else {
print("CHANGED")
let uid = Auth.auth().currentUser!.uid
let thisUserRef = fbRef.child("users").child(uid)
let thisUserEmailRef = thisUserRef.child("email")
thisUserEmailRef.setValue(email.text!)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2180 次 |
| 最近记录: |