I have an Angular application where I am managing users' online/offline status in Firebase. My goal is to delete a user's data from Firebase immediately after their internet connection goes offline. Here is the code snippet I currently have in my Angular project:
const db = getDatabase();
const connectedRef = ref(db, '.info/connected');
var myPresenceRef = this.angularFireDatabase.database.ref(
'/presence/' + this.userInfo['username']
);
onValue(connectedRef, (snap) => {
if (snap.val() === true) {
console.log('Connected to database');
} else {
myPresenceRef.onDisconnect().remove();
}
I want to ensure the data is deleted instantly when the internet connection is lost. How can I achieve this implementation?