From the documentation, I am doing this:
var currentUser;
firebase.auth().onAuthStateChanged(function(user) {
if (user && user.emailVerified) {
currentUser = user;
setPresence();
}
});
function setPresence() {
var myConnectionsRef = firebase.database().ref('users/' + currentUser.uid + '/connections');
var connectedRef = firebase.database().ref('.info/connected');
connectedRef.on('value', function(snap) {
if (snap.val() === true) {
var con = myConnectionsRef.push();
con.onDisconnect().remove();
con.set("profile");
}
});
}
I do this on every page, but it does not seem to be working on the profile page. Here is what I see in the DB:
And this is not a one-off. Almost all users have something like that. What could be the cause of this? Why would onDisconnect not trigger?
Here is the webpage if needed: magicconnects.com/profile.
Thanks so much for your help!
EDIT: Adding security rules:
{
"rules": {
"users": {
"$uid": {
".read": "auth != null",
".write": "auth != null && auth.uid == $uid"
}
}
}
}