+ {error ? (
+ "Error: " + error
+ ) : groupData === null ? (
+ "Error" // we should have had an error in that case
+ ) : groupData.length === 0 ? (
+
You are not part of any group.
+ ) : (
+ <>
+
Your groups:
+
+ {groupData.map((d) => (
+ -
+ {adminData[d.id || ""] ? (
+ {d.name}
+ ) : (
+ d.name
+ )}
+
+ ))}
+
+ >
+ )}
+
+ >
+ );
+};
diff --git a/apps/website/app/utils/supabase/account.ts b/apps/website/app/utils/supabase/account.ts
index a4a0ee36a..fa9444d62 100644
--- a/apps/website/app/utils/supabase/account.ts
+++ b/apps/website/app/utils/supabase/account.ts
@@ -1,5 +1,53 @@
+import type { Database } from "@repo/database/dbTypes";
import type { DGSupabaseClient } from "@repo/database/lib/client";
+type AgentType = Database["public"]["Enums"]["AgentType"] | "group";
+
+export const getSessionUserData = async (
+ client: DGSupabaseClient,
+): Promise<{
+ id: string;
+ name: string;
+ type: AgentType;
+ email?: string;
+} | null> => {
+ const { data, error } = await client.auth.getUser();
+ if (error || !data?.user) return null;
+ const userData = data.user;
+ if (typeof userData.id !== "string") return null;
+ const { id, email }: { id: string; email?: string } = userData;
+ if (email) {
+ const [name, host] = email.split("@") as [string, string];
+ if (host === "database.discoursegraphs.com" && name.endsWith("-anon")) {
+ const parts = name.split("-");
+ const spaceId = Number.parseInt(parts[1]!);
+ if (Number.isNaN(spaceId)) return null;
+ const spaceReq = await client
+ .from("Space")
+ .select("name")
+ .eq("id", spaceId)
+ .maybeSingle();
+ if (spaceReq.error || !spaceReq.data) {
+ return null;
+ }
+ return { name: spaceReq.data.name, id, type: "anonymous", email };
+ }
+ if (host === "groups.discoursegraphs.com") {
+ return { name, id, email, type: "group" };
+ }
+ }
+ const accountReq = await client
+ .from("PlatformAccount")
+ .select("name")
+ .eq("dg_account", id)
+ .eq("agent_type", "person")
+ .maybeSingle();
+ if (accountReq.error || !accountReq.data) {
+ return null;
+ }
+ return { id, name: accountReq.data.name, type: "person", email };
+};
+
export const createGroup = async (
client: DGSupabaseClient,
name: string,
diff --git a/apps/website/test/integration/listMyGroups.test.ts b/apps/website/test/integration/listMyGroups.test.ts
new file mode 100644
index 000000000..8f4dbd33c
--- /dev/null
+++ b/apps/website/test/integration/listMyGroups.test.ts
@@ -0,0 +1,126 @@
+import assert from "assert";
+import { describe, it, beforeAll, afterAll } from "vitest";
+import { createClient } from "@supabase/supabase-js";
+import type { Database } from "@repo/database/dbTypes";
+import type { DGSupabaseClient } from "@repo/database/lib/client";
+import {
+ fetchOrCreateSpaceDirect,
+ spaceAnonUserEmail,
+} from "@repo/database/lib/contextFunctions";
+import { createGroup } from "../../app/utils/supabase/account";
+
+const SUPABASE_URL = process.env.SUPABASE_URL!;
+const ANON_KEY = process.env.SUPABASE_PUBLISHABLE_KEY!;
+const SERVICE_KEY = process.env.SUPABASE_SECRET_KEY!;
+const PASSWORD = "abcdefgh";
+
+const freshClient = (): DGSupabaseClient =>
+ createClient