CODE:
app.js
setInterval(function() {
console.log("1");
var pendingRef = admin.database().ref("pending");
var now = Date.now();
var cutoff = now - 1 * 60 * 60 * 1000;
var old = pendingRef.orderByChild('timestamp').endAt(cutoff).limitToLast(1);
console.log("2");
var listener = old.on('child_added', function(snapshot) {
console.log("3");
console.log("A VALUE:"+snapshot.val());
snapshot.delete().then(function() {
snapshot.ref().remove();
}, function(error) {
console.log("USER WAS NOT DELETED:"+ snapshot.val().key);
});
});
}, 1000 * 10);
SITUATION:
I call it at the end of my app.js
Nothing happens.
Nothing gets printed to the console after "1" and "2".
EDIT:
I cannot call .remove()
on a snapshot
.
Also, from the docs:
"To delete a user, the user must have signed in recently. See Re-authenticate a user."
How can I delete a user then ?
REFERENCE:
Delete firebase data older than 2 hours
https://firebase.google.com/docs/auth/web/manage-users#delete_a_user