Back

I see we can get real time with channel "account"

  • 0
  • Self Hosted
  • Tools
  • Web
Suiii
20 Aug, 2024, 09:35

My attention is to get logged in ( online user list). how this is possible as appwrite server sdk is not ready for realtime yet.

TL;DR
Developers are discussing how to achieve real-time updates with the channel "account" in an app using Next.js. One suggestion is creating a separate UserActive collection and manually updating it when a user logs in. Another developer suggests using the Appwrite function to subscribe to the "account" channel and handle events. This would involve monitoring user sessions to determine online or active status. The key is to utilize event triggers offered by Appwrite.
Joshi
20 Aug, 2024, 09:46

Logging in does not translate to "online users"

Suiii
20 Aug, 2024, 11:19

What so you mean? So when I subscribe to account channel! It returns session is not valid

Suiii
20 Aug, 2024, 11:20

So can we get something like userId of logged in user!

Suiii
20 Aug, 2024, 11:20

I understand other security related info cannot be received!

Joshi
20 Aug, 2024, 11:26

Please be as informative as you can. As your original post does not really explain anything. When a user signs in, that user receives a session object. How do you define "online user" in this context?

Joshi
20 Aug, 2024, 11:26

How does your approach look like? What is your code? You have to provide a lot more information than that

Suiii
20 Aug, 2024, 12:27
TypeScript

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);
});
 ``` based on the document, I. could use real time to subcribe to account channel, so whenever user create session ( login) it would return to the subcriber!  my intension is to collect those user id having the sessions (login) . then in the system can identified them as online or active.
Joshi
20 Aug, 2024, 12:35

In appwrite functions you are supposed to use the event trigger https://appwrite.io/docs/advanced/platform/events

Joshi
20 Aug, 2024, 12:36

Also the user can stop the app in the meantime. So not sure what you mean with "online" and "active"

Joshi
20 Aug, 2024, 12:37

Just because the user logged in at some point does not nessecarily mean that the user is online as long as the session is active

Suiii
20 Aug, 2024, 13:15

user should be considered active until it left broswer

ideclon
20 Aug, 2024, 13:20

And how are you going to know when it leaves?

Suiii
20 Aug, 2024, 14:53

if I use nextjs, onroot layout component disposed, trigger to remove from the collection. then all subcriber should be notified

Suiii
20 Aug, 2024, 15:00

the workaround solution for this I could think of is creating separated collection UserActive , and when user login -> manually update add userId to the collection then giving real time subcription to that collection! however, i see there is way to subcribe to 'account' channel, which should be more appropriate

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more