You could look at adding something like a ‘Logged In Members’ dataset and add into your code so that when a member logs in then the onLogin() function simply makes a dataset boolean field be set as Yes or ticked etc. Then obviously when user logouts you can use code again to set this dataset field to be No or unticked etc.
Then you could just simply query this dataset and show only the logged in members from it in whatever you want to show it in like a table or a repeater etc.
I can’t think off the top of my head if there is a way through Wix Users to do a mass is logged in check as Wix User normally is used to check each current user really. You could even look at creating a backend function that checks each members logged in status if you wanted to.
Also, you can only really use Wix User for this as this checks all members that are logged in members.
You can’t use Wix CRM as this checks all your site contacts and remember that some of those contacts are just contacts and not members so you have no need to be checking them.
On the site panel, use setInterval() to save the member’s userId and timeStamp every x seconds to the CurrentlyOnline collection.
On the backend create an afterQuery hook with item.nickname that gets the nickname from PrivateMembersData.
Make a beforeInsert hook that removes the last record of the same member if exists.
On the Currently Online site page, setInterval() that runs every x seconds and query the CurrentlyOnline with .gt(“timeStamp”, new Date().getTime() - 5000) (for example)
and push the result.items to the repeater.
I got it working! Thing is, I have a “All members” page. My wish is to combine these two. So that I have one repeater on top with “Now online” and another one with “All others”. But I don’t want duplicates, eg. someone is displayed in Now online and in All others. Is that possible>
Sorry for my bad English, it’s not my native language.
You can query the all members collection and then filter out the currently online using javascript, or query the all members collection and eliminate the currently online in your query itself.
The way to combine them depends on the question whether or not you have a Members collection of your own (besides the built-in Private Members collection).