Skip to content

Instantly share code, notes, and snippets.

@slashthinking
Created June 20, 2015 09:24
Show Gist options
  • Save slashthinking/7b5afcf6a54e36963b8a to your computer and use it in GitHub Desktop.
Save slashthinking/7b5afcf6a54e36963b8a to your computer and use it in GitHub Desktop.
检查用户是否存在
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.wilddogio.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
} else {
alert('user ' + userId + ' does not exist!');
}
}
// Tests to see if /users/<userId> has any data.
function checkIfUserExists(userId) {
var usersRef = new Wilddog(USERS_LOCATION);
usersRef.child(userId).once('value', function(snapshot) {
var exists = (snapshot.val() !== null);
userExistsCallback(userId, exists);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment