diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index 703646e..52a98ba 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -52,13 +52,29 @@ export default async function Login({ .select("*") .eq("user_id", session.user.id) .eq("is_home", true) - .single() + .limit(1); // Limit to 1 row + //.single() - if (!homeWorkspace) { - throw new Error(error.message) + // if (!homeWorkspace) { + // throw new Error(error.message) + // } + + + if (!homeWorkspace || homeWorkspace.length === 0) { + // Handle the case where no rows are found + throw new Error("No home workspace found for this user."); } - // console.log("[login page]======>Redirecting to workspace:", homeWorkspace.id) + // If more than 1 row is returned, we handle that case + if (homeWorkspace.length > 1) { + // Handle the case where multiple rows are returned + console.warn("Multiple home workspaces found for this user."); + } + + // Since we used `.limit(1)`, we can safely use `.single()` now + const workspace = homeWorkspace[0]; // Use the first (and only) row + + return redirect(`/${localeString}/${homeWorkspace.id}/chat`) } @@ -87,7 +103,22 @@ export default async function Login({ .select("*") .eq("user_id", data.user.id) .eq("is_home", true) - .single() + .limit(1); // Limit to 1 row + //.single() + + if (!homeWorkspace || homeWorkspace.length === 0) { + // Handle the case where no rows are found + throw new Error(homeWorkspaceError?.message || "No home workspace found for this user."); + } + + // If more than 1 row is returned, we handle that case + if (homeWorkspace.length > 1) { + // Handle the case where multiple rows are returned + console.warn("Multiple home workspaces found for this user."); + } + + // Since we used `.limit(1)`, we can safely use `.single()` now + const workspace = homeWorkspace[0]; // Use the first (and only) row if (!homeWorkspace) { //const fallbackMessage = String(t("login.unexpectedError"))