使用Swift和Firebase更改用户电子邮件和密码 [英] Changing User Email and Password with Swift and Firebase
问题描述
这是我的带有swift和firebase的iOS应用程序的编辑按钮.
Here's my edit button for an iOS application with swift and firebase.
var ref = Firebase(url:"https://·············.firebaseio.com")
@IBAction func Done(sender: AnyObject) {
ref.changeEmailForUser("users/\(self.ref.authData.uid)/email",
password: "users/\(self.ref.authData.uid)/provider", toNewEmail: EmailTextField.text)
{ (ErrorType) -> Void in
if ErrorType != nil {
print("There was an error processing the request")
} else {
print("Email changed successfully")
}
}
ref.changePasswordForUser("users/\(self.ref.authData.uid)/email",
fromOld: "users/\(self.ref.authData.uid)/provider", toNew: PasswordTextField.text)
{ (ErrorType) -> Void in
if ErrorType != nil {
print("There was an error processing the request")
} else {
print("Password changed successfully")
}
}
ref.childByAppendingPath("users").childByAppendingPath(self.ref.authData.uid).updateChildValues(["name":self.NameTextField.text!,"about":self.TextView.text!,"Picker":self.PickerVar])
}
当用户单击完成"按钮时,我想更新他在Firebase中的所有信息. 电子邮件,密码,名称等.
When the user clicks the done button I want to update all of his information in the firebase. Email, Password, Name, etc.
当我单击完成"按钮时,所有信息都会更新,电子邮件和密码除外! 据说处理请求时出错: 如此处图片
All of the information updated when I click the done button, except for email and password! It's says there was an error processing the request: as the picture here
我不知道错误在哪里!我是否以错误的方式使用了changeEmailForUser和changePasswordForUser函数?
I don't know where 's the error! Did I use the changeEmailForUser and changePasswordForUser functions in a wrong way?
这是JSON树:
{
"users" : {
"7b595e99-b20d-4961-bcf0-6c46956a0cbe" : {
"Picker" : "Student",
"about" : "Hey, I'm Here",
"email" : "mariah@gmail.com",
"name" : "Mariah Khayat",
"provider" : "password"
},
"7eb23db6-6b56-4225-9306-22ed0b935b52" : {
"Picker" : "Teacher",
"about" : "Hi",
"email" : "mmm@gmail.com",
"name" : "Memo",
"provider" : "password"
}
}
}
推荐答案
使用Firebase API会造成一些混乱.在我看到API后 https://www.firebase.com/docs/ios/api/#firebase_changeEmailForUserpasswordtoNewEmailwithCompletionBlock 明确指出:
Accarding to Firebase API making some confusion. after i seen the API https://www.firebase.com/docs/ios/api/#firebase_changeEmailForUserpasswordtoNewEmailwithCompletionBlock There is clearly said:
因此对于更新电子邮件,对于用户而言,这不是更新配置文件的一部分.因此,按照以下说明,您可以更改您的电子邮件地址:
So for the update Email For user this is not a part a update profile. So as per following you can change your email address:
ref.changeEmailForUser("OldEmailthatYouuserForLogin", password: "correctpassword",
toNewEmail: "newEmail", withCompletionBlock: { error in
if error != nil {
print("There was an error processing the request")
// There was an error processing the request
} else {
print("Email changed successfully")
// Email changed successfully
}
})
// Dont use edited email for the old email and edited password for the password make sure you are using your actually email and password
这篇关于使用Swift和Firebase更改用户电子邮件和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!