3

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...) :-(

MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • 1
    I'm having the same issue, and I'm pulling my hair out. Why would they make a createUser function without a callback with the uid? – Eric S. Bullington Oct 31 '14 at 17:48
  • 1
    Thanks, I thought I was alone... Hope some Firebase dev will help... @Kato... Rob DiMarco... Are you there??? :-) – MarcoS Nov 01 '14 at 08:26
  • I ended up just having to nest a login call (e.g., `authWithPassword`) in the createUser callback, just to fetch the uid, and then just log the user immediately back out (since user needs to activate via email before logging in). Not the most elegant solution in the world, but for now, it's working. – Eric S. Bullington Nov 01 '14 at 09:33
  • Brilliant. Though, I suppose I will wait for an 'official' solution, staying with 1.0, till then... :-) – MarcoS Nov 02 '14 at 10:18
  • 1
    Just for reference, I had been having this problem with 2.04 and had no idea why the second argument to the callback was `undefined`. It seems that functionality was added in 2.05. I updated the version and it worked. – Dan Prince Feb 12 '15 at 17:24
  • createUser is returning undefined as the second parameter to the callback instead of the user object as promised in the docs. I'm on 2.0.4. ref.createUser({ name : name, lastname : lastname, username : username, email : email, password : password }, function(error, userData) { if (error === null) { console.log(userData); ///this outputs undefined – Rima Feb 16 '15 at 21:59

1 Answers1

4

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);
  }
});
Chris Raynor
  • 1,675
  • 11
  • 13