This commit is contained in:
parent
3bf76625ae
commit
08c7d3fc13
|
|
@ -55,30 +55,14 @@ export default async function Login({
|
||||||
.select("*")
|
.select("*")
|
||||||
.eq("user_id", session.user.id)
|
.eq("user_id", session.user.id)
|
||||||
.eq("is_home", true)
|
.eq("is_home", true)
|
||||||
.limit(1) // Limit to 1 row
|
.maybeSingle();
|
||||||
//.single()
|
|
||||||
|
|
||||||
// if (!homeWorkspace) {
|
if (!homeWorkspace) {
|
||||||
// throw new Error(error.message)
|
await supabase.auth.signOut();
|
||||||
// }
|
return redirect(`/${localeString}/login?message=sessionExpired`);
|
||||||
|
|
||||||
|
|
||||||
if (!homeWorkspace || homeWorkspace.length === 0) {
|
|
||||||
// Handle the case where no rows are found
|
|
||||||
throw new Error("No home workspace found for this user.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1 row is returned, we handle that case
|
return redirect(`/${localeString}/${homeWorkspace.id}/chat`);
|
||||||
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`)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,37 +95,19 @@ export default async function Login({
|
||||||
//.single()
|
//.single()
|
||||||
|
|
||||||
if (!homeWorkspace || homeWorkspace.length === 0) {
|
if (!homeWorkspace || homeWorkspace.length === 0) {
|
||||||
// Handle the case where no rows are found
|
// 找不到home workspace,执行登出清理cookie,重定向到登录页或引导页
|
||||||
throw new Error((homeWorkspaceError as unknown as Error)?.message || "No home workspace found for this user.");
|
await supabase.auth.signOut();
|
||||||
|
// 这里可改为跳转到登录页,带提示参数
|
||||||
|
return redirect(`/${localeString}/login?message=sessionExpired`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1 row is returned, we handle that case
|
// If more than 1 row is returned, we handle that case
|
||||||
if (homeWorkspace.length > 1) {
|
if (homeWorkspace.length > 1) {
|
||||||
// Handle the case where multiple rows are returned
|
// Handle the case where multiple rows are returned
|
||||||
console.warn("Multiple home workspaces found for this user.");
|
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
|
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}/${workspace.id}/chat`)
|
||||||
//return redirect(`/${localeString}/${homeWorkspace.id}/chat`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEnvVarOrEdgeConfigValue = async (name: string) => {
|
const getEnvVarOrEdgeConfigValue = async (name: string) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue