ios - 更新电子邮件到 firebase
<p><p>它在我的控制台中打印 CHANGED,但没有任何变化,用户的电子邮件保持不变。占位符文本恢复为原始电子邮件,并且该特定用户的电子邮件的 Firebase 数据库也未更改。我希望允许用户可以选择更改其个人资料的任何部分,包括电子邮件、密码、位置以及他们在首次注册时存储的其他值。为了做到这一点,我必须将他们注销并让他们重新登录吗?这似乎是一种糟糕的用户体验。 </p>
<pre><code>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
}
}
)}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>.updateEmail 函数更新用户在其 <em>Firebase 凭据</em> 中的电子邮件,并且与存储在/users 节点中的内容无关。</p>
<p>如果您在那里保留了重复的电子邮件,则需要在 .updateEmail 函数成功时将该数据写入/users/uid 节点。即/users 节点是<em>您</em>创建的,不是由 Firebase 维护的。</p>
<pre><code>@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!)
}
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 更新电子邮件到 firebase,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48133637/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48133637/
</a>
</p>
页:
[1]