Created
August 7, 2016 17:42
-
-
Save clarle/2df9bc67a3ef79b29c30d4115cd3bbcf to your computer and use it in GitHub Desktop.
Sign up a user with a unique username in Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)signUpUser:(NSString *)username password:(NSString *)password email:(NSString *)email completion:(void (^)(FIRUser *user, NSError *error))completion { | |
[[FIRAuth auth] | |
createUserWithEmail:email | |
password:password | |
completion:^(FIRUser *user, NSError *error) { | |
FIRDatabaseReference *ref = [[FIRDatabase database] reference]; | |
FIRDatabaseReference *userRef = [[ref child:@"users"] child:username]; | |
[userRef observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) { | |
if (snapshot && snapshot.value[@"uid"] == nil) { | |
[userRef setValue:user.uid forKey:@"uid"]; | |
} | |
} | |
withCancelBlock:^(NSError * _Nonnull error) { | |
NSLog(@"%@", error.localizedDescription); | |
}]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment