1

With iOS/MacOS is there a way to retrieve the uid immediately after createUser?

Our app allows an Admin user to create other user accounts (email/password authentication) and also stores some other info about the created user in our Firebase with the uid as the key.

One solution is when the admin creates the user (createUser), it's followed by authenticating the user, grabbing the uid from FAuthData that's returned and then create the key/value pair in our Firebase with the user data. Then that account is unauth'd.

In doing a Google search, there were a couple of references to something like this

-(void)createUser:(NSString *)email password:(NSString *)password withCompletionBlock(NSError *error, User *user) {block}

where it appears a user (or FAuthData?) was returned.

If no, what is the best practice to get the just-created uid? Is this a feature that is upcoming?

2/22/2016 update

For completeness, soon after I asked this question, Firebase was updated with a method that created the user and returns the uid at the time of creation:

createUser:password:withValueCompletionBlock:

    - (void)createUser:(NSString *)email password:(NSString *)password 
            withValueCompletionBlock:(void ( ^ ) ( NSError *error, NSDictionary *result ))

The result dictionary contains newly-created user attributes, including uid.

Jay
  • 34,438
  • 18
  • 52
  • 81
  • 1
    I don't see a way in the API. But can't you simply log the user in the completion block, straight after creating them? Then you can read the uid from the `authUser:password:withCompletionBlock:` `authData` parameter. – Frank van Puffelen Oct 29 '14 at 23:00
  • Frank has the right answer here. See [angularFire-seed](https://github.com/firebase/angularfire-seed/blob/master/app/js/simpleLogin.js#L60) for an example of this approach. – Kato Oct 30 '14 at 05:40
  • 1
    I believe that our current implementation matches that approach. Create user, authenticate user (log in), get the uid, and then create the user data in our Firebase. – Jay Oct 30 '14 at 13:37
  • 1
    Wouldn't authenticating another user log you out though? – bryan Nov 20 '14 at 17:35
  • I believe the approach you've outlined is the recommended approach by Firebase. ie: log the user in, in the completion block, right after creating the user. – JaredH Feb 21 '16 at 20:20

0 Answers0