Skip to content

Commit

Permalink
fix(web): workspace list is available only for workspace user
Browse files Browse the repository at this point in the history
  • Loading branch information
IKatsuba committed May 6, 2024
1 parent 18076e4 commit fb9f013
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
17 changes: 13 additions & 4 deletions apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('*')
.eq('slug', params.workspaceSlug)
.eq('user_id', user.id)
.single();

if (!workspace) {
return redirect('/not-found');
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,7 +18,7 @@ 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('*').eq('user_id', user.id);

return (
<div>
Expand Down
10 changes: 9 additions & 1 deletion apps/web/app/app/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
1 change: 0 additions & 1 deletion supabase/migrations/20240506132736_invite_email_unique.sql

This file was deleted.

0 comments on commit fb9f013

Please sign in to comment.