Can't connect to Firebase

Solved: Changed read and write rules in Firebase to true

I’ve triple checked my credentials.
What is wrong with this code. The documentation on this sucks.

console.log('>>>LOG<<');
// Get all data from Firebase

rootRef.on('value', initIndex);

// Import Existing Data**
function initIndex(dataSnapshot) {
// Array of data to index
var objectsToIndex = [];
// Get all objects
var values = dataSnapshot.val();
// Process each Firebase ojbect
console.log('>>>0<<<');
for (var key in values) {
if (values.hasOwnProperty(key)) {
// Get current Firebase object
console.log('>>>1<<<');
var firebaseObject = values[key];
// Specify Algolia's objectID using the Firebase object key
firebaseObject.objectID = key;
console.log('>>>2<<<');
// Add object for indexing
objectsToIndex.push(firebaseObject);
console.log('>>>3<<<');
}
}
// Add or update new objects
  index.saveObjects(objectsToIndex, function(err, content) {
if (err) {
 throw err;
}
console.log('>>>4<<<');
console.log('Firebase<>Algolia import done');
});
}

rootRef.on('value', reindexIndex);
function reindexIndex(dataSnapshot) {
// Array of objects to index
var objectsToIndex = [];
// Create a temp index
var tempIndexName = 'meal_temp';
var tempIndex = client.initIndex(tempIndexName);
// Get all objects
var values = dataSnapshot.val();
// Process each Firebase object
for (var key in values) {
if (values.hasOwnProperty(key)) {
// Get current Firebase object
var firebaseObject = values[key];
// Specify Algolia's objectID using the Firebase object key
firebaseObject.objectID = key;
 // Add object for indexing
objectsToIndex.push(firebaseObject);
}
}
// Add or update new objects
index.saveObjects(objectsToIndex, function(err, content) {
if (err) {
throw err;
}
// Overwrite main index with temp index
client.moveIndex(tempIndexName, 'meal', function(err, content) {
if (err) {
throw err;
}
console.log('Firebase<>Algolia reimport done');
});
});
}

// Listen for changes to Firebase data
rootRef.on('child_added', addOrUpdateObject);
rootRef.on('child_changed', addOrUpdateObject);
function addOrUpdateObject(dataSnapshot) {
// Get Firebase object
var firebaseObject = dataSnapshot.val();
// Specify Algolia's objectID using the Firebase object key
firebaseObject.objectID = dataSnapshot.key;
// Add or update object
index.saveObject(firebaseObject, function(err, content) {
if (err) {
throw err;
}
console.log('Firebase<>Algolia object saved');
});
}

// Listen for changes to Firebase data
rootRef.on('child_removed', removeIndex);
function removeIndex(dataSnapshot) {
// Get Algolia's objectID from the Firebase object key
var objectID = dataSnapshot.key;
// Remove the object from Algolia
index.deleteObject(objectID, function(err, content) {
if (err) {
throw err;
}
console.log('Firebase<>Algolia object deleted');
});
}

UPDATE: The code runs, but not all of it gets executed. That’s the issue.

Hi @ethanj.fx, sorry you’re having an issue here. Can you do a few things for me:

  1. Update the post with formatting so that it’s easier to read.
  2. Include a log of the error that you’re seeing.

Thanks.

I’ve reformatted my post. The problem is some of the code does not get executed.

Solved! Read and Write were set to null in Firebase. Changed to true.

Ok, glad you worked it out!