This commit is contained in:
seb
2026-10-28 19:37:28 +01:00
parent 550586f46e
commit b13d994058
2 changed files with 25 additions and 0 deletions

View File

@@ -182,6 +182,23 @@ function connect() {
const es = new EventSource(url.href, { withCredentials: true });
addTrackedListener(es, 'user', (event) => {
try {
const payload = JSON.parse(event.data || '{}');
const nextCompanyId = payload.selectedCompanyId ?? null;
if (authAutomat.state.user?.selectedCompanyId !== nextCompanyId) {
authAutomat.setState((prev) => ({
...prev,
user: prev.user ? { ...prev.user, selectedCompanyId: nextCompanyId } : prev.user,
hasCompany: Boolean((prev.hasAuth ?? (prev.status === 'authed' && prev.user)) && nextCompanyId != null),
}));
}
} catch (err) {
console.error('[sse] failed to handle user event', err);
}
});
addTrackedListener(es, 'company', () => {
const comp = Automat.get('company');
if (comp?.actions?.reload) {