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
- cant resume project
Invalid console fingerprint event i try man time
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...
- Function issue
Hi,idk whats wrong with my function but i made some changes to the env var and made sure they saved then i redeployed it,but then after it redeeployed it asked ...