This commit is contained in:
hailin 2025-05-21 01:18:27 +08:00
parent 3bf76625ae
commit 08c7d3fc13
1 changed files with 9 additions and 43 deletions

View File

@ -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) => {