This commit is contained in:
hailin 2025-05-20 18:57:30 +08:00
parent cc9af51a46
commit e4b1ab7e40
2 changed files with 20 additions and 5 deletions

View File

@ -190,6 +190,7 @@ export default function SetupPage() {
const workspaces = await getWorkspacesByUserId(profile.user_id)
const homeWorkspace = workspaces.find(w => w.is_home)
// There will always be a home workspace
setSelectedWorkspace(homeWorkspace!)

View File

@ -30,18 +30,32 @@ export const getWorkspaceById = async (workspaceId: string) => {
return workspace
}
export const getWorkspacesByUserId = async (userId: string) => {
// export const getWorkspacesByUserId = async (userId: string) => {
// const { data: workspaces, error } = await supabase
// .from("workspaces")
// .select("*")
// .eq("user_id", userId)
// .order("created_at", { ascending: false })
// if (!workspaces) {
// throw new Error(error.message)
// }
// return workspaces
// }
export const getWorkspacesByUserId = async (userId: string): Promise<Workspace[]> => {
const { data: workspaces, error } = await supabase
.from("workspaces")
.select("*")
.eq("user_id", userId)
.order("created_at", { ascending: false })
.order("created_at", { ascending: false });
if (!workspaces) {
throw new Error(error.message)
if (error) {
throw new Error(error.message); // Make sure the error is checked
}
return workspaces
return workspaces as Workspace[]; // Explicitly cast the returned data as a Workspace array
}
export const createWorkspace = async (