Maybe you need a webhook or some other event that’s triggered when users are “online” and “offline”?
The database definitely knows about user online events, without question; we write to the user table “last seen” when that happens. And we also know when users aren’t present as we only send email notifications when users aren’t online in the web browser by default.