Skip to content

Instantly share code, notes, and snippets.

@anantn
Created December 18, 2012 00:54
Show Gist options
  • Save anantn/4323949 to your computer and use it in GitHub Desktop.
Save anantn/4323949 to your computer and use it in GitHub Desktop.

Revisions

  1. anantn created this gist Dec 18, 2012.
    23 changes: 23 additions & 0 deletions firebase_detect_data.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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);
    });
    }