Reputation: 339
Correct me if im wrong but the auth sessions have a 30day max limit? If that is the case, is there a way to keep my server node app listening to an authenticated dataRef persist forever?
Cheers, Trav.
Upvotes: 2
Views: 479
Reputation: 1951
In addition to Kato's suggestion, what you can do is authenticate by passing in your global Firebase secret (available in Forge -> Auth -> Firebase Secrets -> "Show"). This is to be used only in trusted environments (e.g. your backend server), so be sure to not leak it by checking it in to your source control, passing it over to your client-code/end users, etc. This will only "expire" if the secret is revoked.
Upvotes: 1
Reputation: 40582
Since the on method has a cancel callback that is invoked any time permissions are revoked (i.e. auth expires), here's one (untested) possibility to handle the persistent connection:
var fb = new Firebase(URL_AND_PATH);
fb.auth( TOKEN, restart );
function _childAdded(ss) {
/* do something with data */
}
function _authRevoked() {
fb.unauth();
fb.auth( TOKEN, restart );
};
function restart(error) {
if( error ) { console.error(error); }
else {
fb.on('child_added', _childAdded, _authRevoked );
}
}
Upvotes: 2