Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Forked from anantn/firebase_detect_data.js
Last active August 29, 2015 14:16
Show Gist options
  • Save codenamejason/7ac809e8e60e864f9c8a to your computer and use it in GitHub Desktop.
Save codenamejason/7ac809e8e60e864f9c8a to your computer and use it in GitHub Desktop.
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.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 Firebase(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