Skip to content

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

feat(frontend): Make group invitation link work when user is logged in

MidoriKuragee27aefe0d50a
diff --git a/frontend/components/Collection/JoinModal.vue b/frontend/components/Collection/JoinModal.vue
index 370a594e..43dbb6c7 100644
--- a/frontend/components/Collection/JoinModal.vue
+++ b/frontend/components/Collection/JoinModal.vue
@@ -57,10 +57,13 @@
const domain = window.location.protocol + "//" + window.location.host;
const redirectTo = ref("");
+ // Holds invite code from dialog params until the watcher applies it on open
+ const pendingInviteCode = ref("");
onMounted(() => {
const cleanup = registerOpenDialogCallback(DialogID.JoinCollection, params => {
redirectTo.value = params?.redirectTo || "";
+ pendingInviteCode.value = params?.inviteCode || "";
});
onUnmounted(cleanup);
@@ -70,8 +73,8 @@
() => activeDialog.value,
active => {
if (active && active === DialogID.JoinCollection) {
- // reset and focus on open
- form.inviteCode = "";
+ form.inviteCode = pendingInviteCode.value;
+ pendingInviteCode.value = "";
focused.value = true;
}
}
diff --git a/frontend/components/ui/dialog-provider/utils.ts b/frontend/components/ui/dialog-provider/utils.ts
index da9e39f4..96047d7b 100644
--- a/frontend/components/ui/dialog-provider/utils.ts
+++ b/frontend/components/ui/dialog-provider/utils.ts
@@ -73,7 +73,7 @@ export type DialogParamsMap = {
removeTags?: boolean;
};
[DialogID.CreateCollection]?: { redirectTo?: string };
- [DialogID.JoinCollection]?: { redirectTo?: string };
+ [DialogID.JoinCollection]?: { redirectTo?: string; inviteCode?: string };
};
/**
diff --git a/frontend/layouts/default.vue b/frontend/layouts/default.vue
index 087c8615..475c47e1 100644
--- a/frontend/layouts/default.vue
+++ b/frontend/layouts/default.vue
@@ -372,6 +372,7 @@
];
const route = useRoute();
+ const router = useRouter();
const nav: {
icon: Component;
@@ -499,6 +500,23 @@
onMounted(() => {
locationStore.refreshParents();
locationStore.refreshTree();
+
+ // Auto-open JoinModal when invitation token is in URL
+ const token = route.query.token;
+ if (typeof token === "string" && token.length > 0) {
+ // Remove token from browser URL
+ const url = new URL(window.location.href);
+ url.searchParams.delete("token");
+ window.history.replaceState(history.state, "", url.toString());
+
+ // Sync router's state to clear route.query.token
+ const { token: _, ...cleanQuery } = route.query;
+ router.replace({ query: cleanQuery });
+
+ openDialog(DialogID.JoinCollection, {
+ params: { inviteCode: token },
+ });
+ }
});
onServerEvent(ServerEvent.TagMutation, () => {
diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue
index 241aa0e3..2044badf 100644
--- a/frontend/pages/index.vue
+++ b/frontend/pages/index.vue
@@ -31,7 +31,12 @@
middleware: [
() => {
const ctx = useAuthContext();
+ const route = useRoute();
if (ctx.isAuthorized()) {
+ // Preserve invitation token when redirecting authenticated users
+ if (route.query.token) {
+ return `/home?token=${encodeURIComponent(route.query.token as string)}`;
+ }
return "/home";
} else {
console.log("Logged out, clearing collectionId preference");