Skip to content

Commit

Permalink
Merge pull request #28 from Saasfy/user-workspaces
Browse files Browse the repository at this point in the history
fix(web): workspace list is available only for workspace user
  • Loading branch information
IKatsuba authored May 6, 2024
2 parents 18076e4 + 510f775 commit 209e9dc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 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('*, workspace_users(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();

if (!workspace) {
return redirect('/not-found');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Settings() {
</CardHeader>
<CardContent>
<form>
<Input placeholder="Store Name" />
<Input />
</form>
</CardContent>
<CardFooter className="border-t px-6 py-4">
Expand Down
6 changes: 4 additions & 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,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 (
<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
2 changes: 1 addition & 1 deletion apps/web/app/app/(user)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function Settings() {
</CardHeader>
<CardContent>
<form id="nameForm">
<Input placeholder="Store Name" name="name" defaultValue={user.user_metadata.name} />
<Input name="name" defaultValue={user.user_metadata.name} />
</form>
</CardContent>
<CardFooter className="border-t px-6 py-4">
Expand Down
1 change: 0 additions & 1 deletion supabase/migrations/20240506132736_invite_email_unique.sql

This file was deleted.

0 comments on commit 209e9dc

Please sign in to comment.