From 5b37eb012c8b19e4ad915815e0d0dcce9c91ab3f Mon Sep 17 00:00:00 2001 From: garlic-hub <12842269+garlic-hub@users.noreply.github.com> Date: Wed, 29 Apr 2026 21:21:48 -0700 Subject: [PATCH] fix: Don't hit authenticated endpoints when logged out (#7563) --- frontend/app/components/Layout/DefaultLayout.vue | 6 +++--- frontend/app/composables/use-groups.ts | 5 +++++ frontend/app/composables/use-households.ts | 5 +++++ frontend/app/composables/use-recipe-explorer-search.ts | 10 +++++----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/app/components/Layout/DefaultLayout.vue b/frontend/app/components/Layout/DefaultLayout.vue index 6e926bab0..6a5ce8bc6 100644 --- a/frontend/app/components/Layout/DefaultLayout.vue +++ b/frontend/app/components/Layout/DefaultLayout.vue @@ -110,7 +110,7 @@ const route = useRoute(); const groupSlug = computed(() => route.params.groupSlug as string || auth.user.value?.groupSlug || ""); const cookbookPreferences = useCookbookPreferences(); -const ownCookbookStore = useCookbookStore(i18n); +const ownCookbookStore = computed(() => isOwnGroup.value ? useCookbookStore(i18n) : null); const publicCookbookStoreCache = ref>>({}); function getPublicCookbookStore(slug: string) { @@ -121,8 +121,8 @@ function getPublicCookbookStore(slug: string) { } const cookbooks = computed(() => { - if (isOwnGroup.value) { - return ownCookbookStore.store.value; + if (ownCookbookStore.value) { + return ownCookbookStore.value.store.value; } else if (groupSlug.value) { const publicStore = getPublicCookbookStore(groupSlug.value); diff --git a/frontend/app/composables/use-groups.ts b/frontend/app/composables/use-groups.ts index e3ff661f9..3904abcb8 100644 --- a/frontend/app/composables/use-groups.ts +++ b/frontend/app/composables/use-groups.ts @@ -6,7 +6,12 @@ const loading = ref(false); export const useGroupSelf = function () { const api = useUserApi(); + const auth = useMealieAuth(); async function refreshGroupSelf() { + if (!auth.user.value) { + groupSelfRef.value = null; + return; + } loading.value = true; const { data } = await api.groups.getCurrentUserGroup(); groupSelfRef.value = data; diff --git a/frontend/app/composables/use-households.ts b/frontend/app/composables/use-households.ts index 146b142c1..9ca7edd2f 100644 --- a/frontend/app/composables/use-households.ts +++ b/frontend/app/composables/use-households.ts @@ -6,8 +6,13 @@ const loading = ref(false); export const useHouseholdSelf = function () { const api = useUserApi(); + const auth = useMealieAuth(); async function refreshHouseholdSelf() { + if (!auth.user.value) { + householdSelfRef.value = null; + return; + } loading.value = true; const { data } = await api.households.getCurrentUserHousehold(); householdSelfRef.value = data; diff --git a/frontend/app/composables/use-recipe-explorer-search.ts b/frontend/app/composables/use-recipe-explorer-search.ts index 7cdfeb0bb..08e380c2b 100644 --- a/frontend/app/composables/use-recipe-explorer-search.ts +++ b/frontend/app/composables/use-recipe-explorer-search.ts @@ -73,11 +73,11 @@ function createRecipeExplorerSearchState(groupSlug: ComputedRef): Recipe }); // Store references - const categories = isOwnGroup ? useCategoryStore() : usePublicCategoryStore(groupSlug.value); - const foods = isOwnGroup ? useFoodStore() : usePublicFoodStore(groupSlug.value); - const households = isOwnGroup ? useHouseholdStore() : usePublicHouseholdStore(groupSlug.value); - const tags = isOwnGroup ? useTagStore() : usePublicTagStore(groupSlug.value); - const tools = isOwnGroup ? useToolStore() : usePublicToolStore(groupSlug.value); + const categories = isOwnGroup.value ? useCategoryStore() : usePublicCategoryStore(groupSlug.value); + const foods = isOwnGroup.value ? useFoodStore() : usePublicFoodStore(groupSlug.value); + const households = isOwnGroup.value ? useHouseholdStore() : usePublicHouseholdStore(groupSlug.value); + const tags = isOwnGroup.value ? useTagStore() : usePublicTagStore(groupSlug.value); + const tools = isOwnGroup.value ? useToolStore() : usePublicToolStore(groupSlug.value); // Selected items const selectedCategories = ref[]>([]);