问题
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])
}
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
I don't know where 's the error! Did I use the changeEmailForUser and changePasswordForUser functions in a wrong way?
Here's the JSON tree:
{
"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"
}
}
}
回答1:
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
回答2:
Mariah,
The problem is your entered email and password details. You are showing the path for your email and password but instead you should enter what calls them such as. instead of ""users/(self.ref.authData.uid)/email" you should provide it as ref.authData.providerData["email"]as? NSString as? String
for password you need to edit your Firebase rules so user can have access to his own password.
来源:https://stackoverflow.com/questions/35953867/changing-user-email-and-password-with-swift-and-firebase