diff --git a/apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx b/apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx index 4c0fa4c..7985194 100644 --- a/apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx +++ b/apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx @@ -5,16 +5,25 @@ import { redirect } from 'next/navigation'; import { ArrowUpRightIcon, SettingsIcon } from 'lucide-react'; import { CreateProjectSheet } from '@saasfy/components'; -import { createAdminClient } from '@saasfy/supabase/server'; +import { createAdminClient, getUser } from '@saasfy/supabase/server'; import { Button } from '@saasfy/ui/button'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@saasfy/ui/table'; export default async function Component({ params }: { params: { workspaceSlug: string } }) { + const user = await getUser(); + + if (!user) { + return redirect('/login'); + } + const supabase = createAdminClient(); - const workspace = ( - await supabase.from('workspaces').select('*').eq('slug', params.workspaceSlug) - )?.data?.at(0); + const { data: workspace } = await supabase + .from('workspaces') + .select('*, workspace_users(*)') + .eq('slug', params.workspaceSlug) + .eq('workspace_users.user_id', user.id) + .single(); if (!workspace) { return redirect('/not-found'); diff --git a/apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx b/apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx index a800fe4..b014616 100644 --- a/apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx +++ b/apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx @@ -19,7 +19,7 @@ export default function Settings() {
- +
diff --git a/apps/web/app/app/(dashboard)/layout.tsx b/apps/web/app/app/(dashboard)/layout.tsx index 3ec6474..4a9ed2f 100644 --- a/apps/web/app/app/(dashboard)/layout.tsx +++ b/apps/web/app/app/(dashboard)/layout.tsx @@ -1,5 +1,4 @@ import React, { ReactNode, Suspense } from 'react'; -import { headers } from 'next/headers'; import Link from 'next/link'; import { redirect } from 'next/navigation'; @@ -19,7 +18,10 @@ export default async function DashboardLayout({ children }: { children: ReactNod const supabase = createAdminClient(); - const { data: workspaces } = await supabase.from('workspaces').select('*'); + const { data: workspaces } = await supabase + .from('workspaces') + .select('*, workspace_users(*)') + .eq('workspace_users.user_id', user.id); return (
diff --git a/apps/web/app/app/(dashboard)/page.tsx b/apps/web/app/app/(dashboard)/page.tsx index 89929f7..93c1574 100644 --- a/apps/web/app/app/(dashboard)/page.tsx +++ b/apps/web/app/app/(dashboard)/page.tsx @@ -1,19 +1,27 @@ import React from 'react'; import Link from 'next/link'; +import { redirect } from 'next/navigation'; import { ArrowUpRightIcon } from 'lucide-react'; import { CreateWorkspaceSheet } from '@saasfy/components'; -import { createAdminClient } from '@saasfy/supabase/server'; +import { createAdminClient, getUser } from '@saasfy/supabase/server'; import { Badge } from '@saasfy/ui/badge'; import { Button } from '@saasfy/ui/button'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@saasfy/ui/table'; export default async function Component() { + const user = await getUser(); + + if (!user) { + return redirect('/login'); + } + const supabase = createAdminClient(); const { data: workspaces } = await supabase .from('workspaces') .select('*, projects(id), domains(id), workspace_users(id), plans(name)') + .eq('user_id', user.id) .limit(8); return ( diff --git a/apps/web/app/app/(user)/settings/page.tsx b/apps/web/app/app/(user)/settings/page.tsx index c2895df..81c0a7f 100644 --- a/apps/web/app/app/(user)/settings/page.tsx +++ b/apps/web/app/app/(user)/settings/page.tsx @@ -53,7 +53,7 @@ export default async function Settings() {
- +
diff --git a/supabase/migrations/20240506132736_invite_email_unique.sql b/supabase/migrations/20240506132736_invite_email_unique.sql deleted file mode 100644 index 496311b..0000000 --- a/supabase/migrations/20240506132736_invite_email_unique.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE workspace_invites ADD CONSTRAINT unique_email_per_workspace UNIQUE (email, workspace_id);