Skip to content

Instantly share code, notes, and snippets.

@yimengtianya
Last active February 13, 2017 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yimengtianya/8c026cfb17e1587e2ae9 to your computer and use it in GitHub Desktop.
Save yimengtianya/8c026cfb17e1587e2ae9 to your computer and use it in GitHub Desktop.
Wilddog: 检测用户数据是否存在
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://<your-appid>.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