I want to identify who is on my app so I can place green badges as indicators.
I logged into my app (which I have not deployed) through Google OAuth, so the session is stored. However, I left days ago and it is still there. So, I don’t know the best algorithm or query to implement to accomplish this. Hopefully, other developers have been able to overcome this issue.
2
Answers
In general a possibility you could opt for is to store the last request time for each user and consider anyone green by default whose latest request happened in the latest 30 minutes or so. Of course, some scenarios may override it, such as a user clicking on logout could be set to inactive even if he had quite recent requests.
Or, if you use WebSockets, then you could track who has open channels.
If you want to display the list of users that are online, presence is the feature built exactly for that.
https://supabase.com/docs/guides/realtime/presence