
I'm currently trying out the realtime events and first i wanted to try out how the account related subscriptions work but even though the websocket is on (if im making changes i get errors about the socket is disconnected and reconnect try will happen) i dont get any response. The basic idea is that if I change my user name or email it will change it on the user context.
const [user, setUser] = useState<User| null>(null);
const client = Connection();
const account = new Account(client);
useEffect(() => {
console.log('useEffect');
//subscribe to user changes
const _subscribe = client.subscribe('account', response => {
// Callback will be executed on all account events.
console.log(response);
});
return () => {
_subscribe();
}
}, []);
useEffect(() => {
async function getUser() {
const user = await account.get();
if (user) {
const {name, email, prefs, labels} = user;
setUser({id: user['$id'], name, email, prefs, labels});
document.cookie = `a=${user['$id']}; path=/; max-age=31536000;`;
toast.success('Sikeres bejelentkezés!');
}
return
}
getUser();
}, []);
Connection() is just a bundler for the new Client() but other than that everything is like in the docs. You need to put the subscription to a useEffect bcs of the SSR, and i cant have the user object as a useEffect dependency cuz then i will have an websocket error: WebSocket is closed before the connection is established Also tried to if a user is present before subscription but still nothing happend if there was an event on account
I could not find any relatable and detailed solutions so im open for any kind of help, thanks.

If you go into the network tab and click on ws, do you see it sending over an auth message?


only these even after an event

Click in the pending one and see the messages

is there an auth message


How are you authenticating in your app? SSR?
Recommended threads
- Can multiple functions exist in one Appw...
Can I add more than one function in the `src/main.js` file of an Appwrite cloud function? What if the different functions depend on two separate events, speci...
- Support for multi-user pushTargert with ...
I'm working on an app that supports multiple logged-in users. That is, a user can add multiple accounts. Something akin to the image below. Only one user can be...
- Postman function call
Hi I'm trying to call a locally running function, which requires auth, in headers I'm passing jwt token with key as 'x-appwrite-user-jwt", but upon logging req....
