I need to "listen" to account events responsively to update my UI when user sign in and out (so, when a session is created and deleted), but if i subscribe as guest, it seems events are never fired. Do you know another way to achieve to listen to login/logout events??
Summary
Title: [SOLVED] How to subscribe account events as guest?
Solution: Instead of using the Appwrite JavaScript library, it is recommended to use state management and call account.get() after creating a session. This will allow you to listen to login/logout events responsively and update your UI accordingly.
Richard Trudel
Rank 1: Thread
Feb 28, 2023, 21:14
The best example of what I'm trying to achieve is to reproduce onAuthStateChanged behavior from Firebase
Drake
Feb 28, 2023, 21:20
Honestly, don't try to reproduce this from firebase. Build an app as if that wasn't a thing
Richard Trudel
Rank 1: Thread
Feb 28, 2023, 21:22
I guess I will need to use some state management to avoid to call account.get() in setInterval or something very ugly...
Drake
Feb 28, 2023, 21:26
instead of that, i would call account.get() after creating a session and store that in your state management. that's it
Richard Trudel
Rank 1: Thread
Feb 28, 2023, 21:27
Ok, I'll try this.
And just to be sure, that also mean this code cannot be used until the user is signed in?
JavaScript
appwrite.subscribe('account',asyncresponse=>{
// do something
});
Drake
Feb 28, 2023, 21:27
i wouldn't do that.
after deleting the session, clear the user from your state management. that's it
Richard Trudel
Rank 1: Thread
Feb 28, 2023, 21:29
Ok, that make sense, but I wanted to give a try without using a store, only using Appwrite Javascript 🙂
Drake
Feb 28, 2023, 21:30
that's fine too
Richard Trudel
Rank 1: Thread
Feb 28, 2023, 21:31
Thank you 🙂
Drake
Feb 28, 2023, 21:32
[SOLVED] How to subscribe account events as guest?