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
- All My Project is Gone
Hello everyone, please help. Why have all my projects suddenly disappeared? I received a warning via email about one of my projects being paused. When I clicked...
- CORS errors in Obsidian custom plugin
Hi, anyone here familiar with obsidian community plugins? In short: it's a local first note app which supports writing your own add-ons / plugin But I keep get...
- > AppwriteException: The requested servi...
When trying to read or write from my database I get the following error: > AppwriteException: The requested service is disabled. You can enable the service from...