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
- GB Hours IS NOT resetting
Hi, I was checking my usage and noticed that all of my usage quotas were reset on August 20, 2026, when my billing cycle renewed. Everything else appears to ha...
- Confused about Appwrite Pro pricing
Hi. I've been subscribed to the $25 Appwrite Pro plan, but I've been getting charged $40. I have two projects on my account. I was wondering where exactly the e...
- How can I disable client-side account re...
Hi everyone! I’m currently building a game backend using Appwrite, and I’d like to prevent users from creating new accounts directly through the client. My go...