From e5182c036946bddd393f1e015fb80a56a45113bc Mon Sep 17 00:00:00 2001 From: Tobias Frischmann Date: Thu, 10 Sep 2026 14:58:22 +0200 Subject: [PATCH] respect org for sse --- app/components/Settings/GoogleLogin.vue | 14 +++++++++++--- app/composables/useInitData.ts | 22 ---------------------- app/composables/useSSE.ts | 13 ++++++++++--- app/pages/index.vue | 11 +++++++++-- 4 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 app/composables/useInitData.ts diff --git a/app/components/Settings/GoogleLogin.vue b/app/components/Settings/GoogleLogin.vue index a55fb4c..cb82ec5 100644 --- a/app/components/Settings/GoogleLogin.vue +++ b/app/components/Settings/GoogleLogin.vue @@ -19,18 +19,26 @@ return !!id.value; }); - const { clear, reset } = await useInitdata(); + const queryCache = useQueryCache(); async function login() { await authClient.signIn.social({ provider: "google", }); - reset(); + + initSSE(); + queryCache.invalidateQueries(); } async function logout() { await authClient.signOut(); - clear(); + + stopSSE(); + + queryCache.setQueryData(["todos", "active"], []); + queryCache.setQueryData(["todos", "deleted"], []); + queryCache.setQueryData(["tags"], []); + queryCache.setQueryData(["categories"], []); } diff --git a/app/composables/useInitData.ts b/app/composables/useInitData.ts deleted file mode 100644 index 7b33810..0000000 --- a/app/composables/useInitData.ts +++ /dev/null @@ -1,22 +0,0 @@ -export async function useInitdata() { - const queryCache = useQueryCache(); - - function clear() { - stopSSE(); - - queryCache.setQueryData(["todos", "active"], []); - queryCache.setQueryData(["todos", "deleted"], []); - queryCache.setQueryData(["tags"], []); - queryCache.setQueryData(["categories"], []); - } - - function reset() { - initSSE(); - queryCache.invalidateQueries(); - } - - return { - clear, - reset, - }; -} diff --git a/app/composables/useSSE.ts b/app/composables/useSSE.ts index f073a21..b2a34bb 100644 --- a/app/composables/useSSE.ts +++ b/app/composables/useSSE.ts @@ -47,11 +47,18 @@ export async function AuthSSE(url: string): Promise { const { public: { apiBase }, } = useRuntimeConfig(); + const { selectedOrg } = useSettings(); const { getToken } = useAuthToken(); const token = await getToken(); - return new SSE(`${apiBase}${url}`, { - headers: { Authorization: `Bearer ${token}` }, - }); + const headers: Record = { + Authorization: `Bearer ${token}`, + }; + + if (selectedOrg.value !== undefined) { + headers["x-org-id"] = selectedOrg.value; + } + + return new SSE(`${apiBase}${url}`, { headers }); } diff --git a/app/pages/index.vue b/app/pages/index.vue index 91d14bc..cd8ac59 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -11,10 +11,18 @@ const isFilterSheetOpen = ref(false); const isNewSheetOpen = ref(false); + const { design, selectedOrg } = useSettings(); + onMounted(async () => { // Timeout to avoid browser confusing sse as page load progress setTimeout(() => { - initSSE(); + watch( + selectedOrg, + () => { + initSSE(); + }, + { immediate: true }, + ); }, 1000); }); @@ -40,7 +48,6 @@ const { isMobile } = useDevice(); const isPwa = useIsPwa(); - const { design } = useSettings(); useHead({ htmlAttrs: { -- 2.51.2