2

I have the following problem, I am sending data every minute to a firebase database in a cron tab that is running in nodejs, I only send the information when there are changes, but when there are no changes the database continues to receive information, This is my code

let admin = require('firebase-admin');
let prev_res = {};

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'mydburl'
});

cron.schedule('* * * * *', function(){
    let connection = mysql.createConnection({
      host     : 'myhost',
      user     : 'myuser',
      password : 'mypass',
      database : 'mydb'
    });

    connection.query("MY QUERY", function(err, rows, fields){
        if (!err){
            if(JSON.stringify(rows) != JSON.stringify(prev_res)){
                let db = admin.database();
                let ref = db.ref('path');
                ref.set(rows);

                console.log("Updated data");
            } else {
                console.log("without changes");
            }

            prev_res = rows;

        }
    });

});

Does the firebase admin have some kind of cache or something like that?

2
  • If firebase receives data, that mean the if condition is failing. So, you should check the code. Commented May 31, 2017 at 20:32
  • In the console it shows the message "without changes", I suppose that the condition is well. Commented Jun 1, 2017 at 15:25

1 Answer 1

1

This is actually a strange problem with Firebase Authentication. The issue resides in the permissions for the user you are including in your credentials. Besides creating a Service Account with the correct permissions, you need to add this user to your IAM Accounts with the editor role.

Restart your App after doing this and you should stop seeing:

"FIREBASE WARNING: Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.