Request a unique username in Firebase

I am new with Firebase. I am developing an angular + firebase application, where after registering a user by email + password, he can save his username after sending the profile form.

Before that, I want to know if the user in the application has his username. This aproch does not work, because scope.used is always false:

scope.used = false; scope.updateProfile = function(profile) { var ref = new Firebase(FIREBASE_URL + '/users'); ref.orderByChild("username").equalTo(profile.username).on("child_added", function(snapshot) { if (currentUser != snapshot.key()) { scope.used = true; } }); if (scope.used) { console.log('username already exists'); } }; 

Is there any other way to do this?

EDIT (I answer to myself)

This approach works:

  scope.used = false; var userRef = new Firebase(FIREBASE_URL + '/users/' + currentUser); scope.updateProfile = function(profile) { var ref = new Firebase(FIREBASE_URL + '/users'); ref.orderByChild("username").equalTo(profile.username).on("child_added", function(snapshot) { if (currentUser != snapshot.key()) { scope.used = true; } }); ref.orderByChild("username").equalTo(profile.username).once("value", function(snap) { //console.log("initial data loaded!", Object.keys(snap.val()).length === count); if (scope.used) { console.log('username already exists'); scope.used = false; }else{ console.log('username doesnt exists, update it'); userRef.child('username').set(profile.username); } }); }; 
0
angularjs firebase
Feb 25 '16 at 19:40
source share

No one has answered this question yet.

See similar questions:

8
Providing unique Firebase simplelogin usernames

or similar:

8
Providing unique Firebase simplelogin usernames
3
UpdateProfile () during a Firebase fight
2
Access variable in closing Firebase
2
Firebase cloud function script not working
one
Firebase checks if a value exists without reading a snapshot or trying to write (for unique usernames)?
one
Scaling with Firebase
0
$ authWithPassword is not a function in Firebase
0
Firebase Array or Object - How to get child data or check if data exists
0
Swift + Firebase - check if node value exists with autoId
0
How to create custom URLs for new users using Firebase?



All Articles