I'm using firebase and I wrote a simple function in Javascript to SET and UPDATE data.
function setLastOnline(userID, InOut){
var dbLastonline = firebase.database().ref().child("lastonline");
if (InOut) {
dbLastonline.child(userID).set({
"isConnected":true,
"connectedby":"web",
"lastIn":firebase.database.ServerValue.TIMESTAMP,
"lastOut":0
});
} else {
dbLastonline.child(userID).update({
"isConnected":false,
"connectedby":"web",
"lastOut":firebase.database.ServerValue.TIMESTAMP
});
}
}
When I call the function to perform the SET method, nothing happens... No data in database and no error code...
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
setLastOnline(user.uid, true);
}
}
But when I call the same function to perform the UPDATE, everything works fine.
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
setLastOnline(user.uid, false);
firebase.auth().signOut();
}`
}`
What am I doing wrong?
Thanks in advance.