Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: backend being reset broke collections

tonyaellie1909e9f4a78a
diff --git a/frontend/composables/use-api.ts b/frontend/composables/use-api.ts
index cf031bee..0f270c24 100644
--- a/frontend/composables/use-api.ts
+++ b/frontend/composables/use-api.ts
@@ -56,7 +56,14 @@ export function useUserApi(): UserClient {
const body = (await r.json().catch(() => null)) as { error?: string } | null;
if (body?.error === "user does not have access to the requested tenant") {
- if (prefs?.value) {
+ console.log("user does not have access to the requested tenant");
+ if (window.location.pathname == "/") {
+ // do nothing
+ console.log("at root path, ignoring collectionId to prevent infinite redirect loop");
+ } else if (!prefs?.value?.collectionId) {
+ console.log("no collectionId set, ignoring");
+ } else {
+ console.log("clearing collectionId");
prefs.value.collectionId = null;
}
}
diff --git a/frontend/composables/use-collections.ts b/frontend/composables/use-collections.ts
index 616bbb3a..c31e6e7c 100644
--- a/frontend/composables/use-collections.ts
+++ b/frontend/composables/use-collections.ts
@@ -14,51 +14,79 @@ const refreshing = ref(false);
export const useCollections = () => {
const load = async () => {
- if (refreshing.value) return;
+ if (window.location.pathname === "/") {
+ console.debug("[useCollections] On root path '/', skipping load");
+ return;
+ }
+
+ if (refreshing.value) {
+ console.debug("[useCollections] Load already in progress, skipping");
+ return;
+ }
refreshing.value = true;
+ console.debug("[useCollections] Starting load");
try {
const api = useUserApi();
const prefs = useViewPreferences();
+ console.debug("[useCollections] Fetching current user");
const { data: userResp } = await api.user.self();
const user = userResp?.item;
+ console.debug("[useCollections] User loaded", { userId: user?.id, defaultGroupId: user?.defaultGroupId });
+ console.debug("[useCollections] Fetching all groups");
const { data: allGroups } = await api.group.getAll();
const available = Array.isArray(allGroups)
? (allGroups as Array<{ id: string; name: string }>).map(g => ({ id: g.id, name: g.name }))
: [];
collections.value = available;
+ console.debug("[useCollections] Collections loaded", {
+ count: collections.value.length,
+ collections: collections.value,
+ });
try {
const route = useRoute();
if (collections.value.length === 0) {
- if (import.meta.client && route.path !== "/no-collections") {
+ console.warn("[useCollections] No collections available for user");
+ if (import.meta.client && route.path !== "/no-collections" && route.path !== "/") {
+ console.log("[useCollections] Navigating to /no-collections (no available collections)");
void navigateTo("/no-collections");
}
}
} catch (e) {
- console.error("Navigation error in useCollections:", e);
+ console.error("[useCollections] Navigation error:", e);
}
+
const prefId = prefs.value.collectionId ?? null;
+ console.debug("[useCollections] Selection preference:", { prefId });
+
if (prefId && collections.value.find(c => c.id === prefId)) {
selectedId.value = prefId;
+ console.debug("[useCollections] Using preferred collection", { selectedId: prefId });
} else if (user?.defaultGroupId && collections.value.find(c => c.id === user.defaultGroupId)) {
selectedId.value = user.defaultGroupId;
prefs.value.collectionId = selectedId.value;
+ console.debug("[useCollections] Using user default collection", { selectedId: user.defaultGroupId });
} else if (collections.value.length > 0) {
const first = collections.value[0];
if (first) {
selectedId.value = first.id;
prefs.value.collectionId = selectedId.value;
+ console.debug("[useCollections] Using first available collection", { selectedId: first.id });
}
} else {
selectedId.value = null;
prefs.value.collectionId = null;
+ console.warn("[useCollections] No collection selected - empty list");
}
+ } catch (e) {
+ console.error("[useCollections] Error loading collections:", e);
} finally {
refreshing.value = false;
+ console.debug("[useCollections] Load complete", { selectedId: selectedId.value });
}
};
diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue
index f63f4e2e..ab148035 100644
--- a/frontend/pages/index.vue
+++ b/frontend/pages/index.vue
@@ -33,6 +33,12 @@
const ctx = useAuthContext();
if (ctx.isAuthorized()) {
return "/home";
+ } else {
+ console.log("Logged out, clearing collectionId preference");
+ const prefs = useViewPreferences();
+ if (prefs.value.collectionId) {
+ prefs.value.collectionId = null;
+ }
}
},
],