Firebase createUser() does not return id of created user

∥☆過路亽.° 提交于 2019-12-23 20:16:29

问题


I'm using Firebase 1.1 (which embeds old firebase-simple-login functionalities).

Now, when creating a user, how do I get it's id (or uid)?

app.controller('AuthCtrl', function ($scope, $firebase) {
  var ref = new Firebase(MY_FIREBASE_URL);
  ref.createUser({
    email: 'mary@mail.com',
    password: 'her-super-secret-password'
  },
  function(err) {
    switch (err.code) {
      ...
    }
  }
}

As far as I can understand, createUser function callback only reports an err object in case of error. But - in case of success - I need the created user id (or better uid), to use it to add the user to my internal users profiles...

How do I get created user id from Firebase createUser ?

UPDATE: I did just give up with 1.1, reverting to 1.0 until some more docs are available (or some answer I get...) :-(


回答1:


Firebase recently released an updated JavaScript client (v2.0.5) which directly exposes the user id of the newly-created user via the second argument to the completion callback.

Check out the changelog at https://www.firebase.com/docs/web/changelog.html and see below for an example:

ref.createUser({
  email: '...',
  password: '...'
}, function(err, user) {
  if (!err) {
    console.log('User created with id', user.uid);
  }
});


来源:https://stackoverflow.com/questions/26483754/firebase-createuser-does-not-return-id-of-created-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!