mayhan mayhan - 2 months ago 43
Node.js Question

Firebase admin sdk (node.js) database request freezing

In recent days, i have encountered a few problems with my old firebase sdk's in both android and server node js 'firebase' sdk. Sending notifications and retrieving data.
After i updated android dependencies with newest version, notification problem was solved.
But in server side:

Problem with the following example:

var admin = require("firebase-admin");
var serviceAccount = require("filepath.json");

credential: admin.credential.cert(serviceAccount),
databaseURL: ""

var db = admin.database();
var ref = db.ref("myval");


Example does not return any value or error, just waiting. Sure there is 'myval' child under main database tree.

What wrong may cause the problem?


Solved the problem with help of firebase team.

Enabling the logging before database definition with:

var db = admin.database();

helps for debugging. After that I got the error:

Failed to get token: Error: Error fetching access token: invalid_grant (Invalid JWT: Token must be a short-lived token and in a reasonable timeframe)

And according to this: Authentication on google: OAuth2 keeps returning 'invalid_grant' my machine timezone was not syncronized appropriately with a ntp server, which is required for new admin authentication in my case.

Then (in ubuntu 14.04) setting the timezone (timezones are here: '$ timedatectl list-timezones') :

$ sudo timedatectl set-timezone desired_timezone

solved the problem!

Thanks for helps.