Is there a way to get on a react app with realtime db, all active users' sessions? In simple all users that are currently logedin?
that is a server operation so you would need to use the server api. you'd have to iterate over each user and list the sessions:
https://appwrite.io/docs/server/users?sdk=nodejs-default#usersListSessions>
is there a way to use the server sdk (node.js) in a react native or react app? Alternatively could you suggest me another way to succeed such functionality...
I tried also the realtime database events but unfortunately I cannot get the account.session.create event.... I get only the delete event
i'ts a security concern running it client side because then end users will have full access to all other users...if you really want to, you can expose the data via an Appwrite Function
I figured out it to be honest (with a function).... Ok the alternative way via the account realtime events ? Is it a possible solution? I mean if I get realtime session details I get currently users logedin so I can get them in a list... I suppose
uhh sure....for current user, you could possibly see those events come through...but a user can just fetch their own sessions:
https://appwrite.io/docs/client/account?sdk=web-default#accountListSessions
actually I mean this:
import { Client } from "appwrite";
const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') .setProject('[PROJECT_ID]');
client.subscribe('account', response => { // Callback will be executed on all account events. console.log(response); });
and from the response I can get the session.$id of each user....
why do you need to subscribe and are you asking for a single user to get sessions of a different user?
The result that I seek is to create a chat app with multiple rooms (one to one user to user) and actually each user to be able to communicate with multiple users those who are in the users list page
you'll probably need to create a database collection for users and then use teams for permissions
And why do you need sessions?
I thought I could use session and from there get session id and consequently userid from the sessionid and create an array of currently logged in users ….. something like that!! But ok also the suggestion of creating another collection sounds good …. Could you give me a short walk through on this? I mean how to combine user collection and teams and how am I supposed to get to the desired solution….. if possible of course
Think of this collection as a Profiles collection that has public data for a user. My only suggestion is you should create the document in the colection when the user creates an account using an Appwrite function. Similar to my Users collection here: https://levelup.gitconnected.com/building-a-location-based-app-with-appwrite-48a2e2b6d4c2
The rest is up to you and how you want to design your app.
Sounds ok …. The reason that I am thinking sessions is that I need to determine whether a user is currently logged in or not. In other words if a user is live so that another logged in user can text him or not … Another way that I figured it out is that on the users collection I might add an extra attribute named session and whenever a user logs in I might run an update document function so that I can get a realtime event. What do you think? ....my only concern in this case is that whenever I might have multiple sessions from the same user each session will be update the previous one and finally I am thinking that on log out process I might call deleteSessions() instead of deleteSession('current')...
just because there's a session, doesn't mean they are active. and you're right about the multiple sessions problem too. I wouldn't use sessions as a way to determine whether someone is active or not.
This type of thing is typically done with a presence API (you can read more about it on your own), but Appwrite doesn't have that.
I would suggest using a heartbeat approach to detect if someone is active or not. What you can do is have a heartbeats collection where a document in there is a user's heartbeat. The user would update a timestamp in their heartbeat document while they are active in your app. If the timestamp is older than X minutes, you can consider them inactive.
Recommended threads
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here 🙂 I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...