From 08c7d3fc1336274373d9ddad5c51a49b50d14109 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 21 May 2025 01:18:27 +0800 Subject: [PATCH] . --- chatdesk-ui/app/[locale]/login/page.tsx | 52 +++++-------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/chatdesk-ui/app/[locale]/login/page.tsx b/chatdesk-ui/app/[locale]/login/page.tsx index dabd9b7..25efb4e 100644 --- a/chatdesk-ui/app/[locale]/login/page.tsx +++ b/chatdesk-ui/app/[locale]/login/page.tsx @@ -55,30 +55,14 @@ export default async function Login({ .select("*") .eq("user_id", session.user.id) .eq("is_home", true) - .limit(1) // Limit to 1 row - //.single() + .maybeSingle(); - // 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."); + if (!homeWorkspace) { + await supabase.auth.signOut(); + return redirect(`/${localeString}/login?message=sessionExpired`); } - // 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}/${workspace.id}/chat`) - //return redirect(`/${localeString}/${homeWorkspace.id}/chat`) + return redirect(`/${localeString}/${homeWorkspace.id}/chat`); } @@ -111,37 +95,19 @@ export default async function Login({ //.single() if (!homeWorkspace || homeWorkspace.length === 0) { - // Handle the case where no rows are found - throw new Error((homeWorkspaceError as unknown as Error)?.message || "No home workspace found for this user."); + // 找不到home workspace,执行登出清理cookie,重定向到登录页或引导页 + await supabase.auth.signOut(); + // 这里可改为跳转到登录页,带提示参数 + return redirect(`/${localeString}/login?message=sessionExpired`); } - // 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 || homeWorkspace.length === 0) { - // Assert that homeWorkspaceError is of type PostgrestError or similar - if (homeWorkspaceError) { - throw new Error((homeWorkspaceError as PostgrestError).message || "No home workspace found for this user."); - } - throw new Error("No home workspace found for this user."); - } - - // if (!homeWorkspace) { - // //const fallbackMessage = String(t("login.unexpectedError")) - // throw new Error( - // homeWorkspaceError?.message || "An unexpected error occurred" - // // homeWorkspaceError?.message || t("login.unexpectedError") - // ) - // } - return redirect(`/${localeString}/${workspace.id}/chat`) - //return redirect(`/${localeString}/${homeWorkspace.id}/chat`) } const getEnvVarOrEdgeConfigValue = async (name: string) => {