Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase web - close connection to the realtime database

I'm using Firebase on the web, with Javascript.
how can I close the connection to the realtime DB ?

var config = {....};
firebase.initializeApp(config);

// get the firebase DB reference
var db = firebase.database().ref();

//doing something
db.push(....);

// close the firebase connection ???
db.close() || firebase.disconnect() || or something like that...

Tried lots of functions - goOffline() , close() , ect.
But nothing does the trick.

Any help would be appreciated... tnx mates

like image 439
Sahar Millis Avatar asked Dec 15 '22 03:12

Sahar Millis


2 Answers

Try this-

firebase.initializeApp(config);

// Kill this firebase app.
firebase.app().delete().then(function() {
  firebase.initializeApp(newConfig);
});

goOffline() will close connection but Firebase will continue to work locally and the app will remain in memory.

like image 76
kdizzle Avatar answered Dec 17 '22 02:12

kdizzle


Try using:

firebaseRef.off();

This will end your connection with firebase and stop communicating with the database.

like image 40
M.A.Williams Avatar answered Dec 17 '22 00:12

M.A.Williams