Pregunta

It seems like the only thing that can be changed is the password (via auth.changePassword()). How do I let a user change their email address or display name?

¿Fue útil?

Solución

The firebase Auth object is pretty simple but it will provide you the user id generated when the user authenticates to your system. You would then take this user id and map it to a Users location where you can store additional information such as display name.

For example, after the user has authenticated and you have your auth object with id value, you could do:

new Firebase('https://your_fb_url.firebase.io').child('users/'+id).set({email: email, name: name}, function(err) {})

You'd want to have read/write rules setup on that location to only allow the authenticated user to see & make changes. Something like:

{
  "rules": {
    "users": {
      "$user": {
        ".read": "$user == auth.uid",
        ".write": "$user == auth.uid",
      }
    }
  }
}

6/12/2015 - UPDATE - Below is Outdated

As for changing the actual login e-mail (for Firebase Simple Login Web), that I'm not so sure about. I know they provide a change password method but I haven't seen any documentation about a change login/email method.

The underlying code for firebase simple password doesn't appear to include any methods for changing the login e-mail address associated with the account. The changePassword method eventually performs a jsonp call out to /auth/firebase/update with the email, old password, and new password.

I'd hate to suggest using a combination of removeUser/createUser to remove the old account, create a new account, and update any user id associations you have you in your app - but I don't see a straightforward "changeEmail" method. The remove/create route would require the user to enter their password again - though that's a pretty common practice for updating logins these days anyway.

6/12/2015 - UPDATE - New API

Firebase has moved away from Firebase Simple Login as a separate module and now the core Firebase 2.x library has authentication related methods baked in. Including a method to change the e-mail account used for the authWithPassword methods.

See updated 2.x docs for changeEmail()

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top