Skip to content

Commit 50910c0

Browse files
authored
Merge pull request #46 from Saasfy/fix-workflow-filtering
fix(web): fix workspace access problems
2 parents baa61a3 + cf8ec3d commit 50910c0

File tree

10 files changed

+37
-17
lines changed

10 files changed

+37
-17
lines changed

.github/FUNDING.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: [IKatsuba,Saasfy]
3+
github: [IKatsuba, Saasfy]
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username

apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function Component({ params }: { params: { workspaceSlug: s
2020

2121
const { data: workspace } = await supabase
2222
.from('workspaces')
23-
.select('*, workspace_users(*)')
23+
.select('*, workspace_users!inner(*)')
2424
.eq('slug', params.workspaceSlug)
2525
.eq('workspace_users.user_id', user.id)
2626
.single();

apps/web/app/app/(dashboard)/[workspaceSlug]/settings/domains/page.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1+
import { redirect } from 'next/navigation';
2+
13
import { ExternalLinkIcon } from 'lucide-react';
24

3-
import { createAdminClient } from '@saasfy/supabase/server';
5+
import { createAdminClient, getUser } from '@saasfy/supabase/server';
46
import { Badge } from '@saasfy/ui/badge';
57

68
import { AddDomainForm } from './add-form';
79
import { DomainConfiguration } from './domain-configuration';
810
import { RemoveDomainButton } from './remove-domain-button';
911

1012
export default async function Component({ params }: { params: { workspaceSlug: string } }) {
13+
const user = await getUser();
14+
15+
if (!user) {
16+
return redirect('/login');
17+
}
18+
1119
const supabase = createAdminClient();
1220

1321
const { data: workspace } = await supabase
1422
.from('workspaces')
15-
.select('*')
23+
.select('*, workspace_users!inner(*), domains(*)')
1624
.eq('slug', params.workspaceSlug)
25+
.eq('workspace_users.user_id', user.id)
1726
.single();
1827

1928
if (!workspace) {
2029
return null;
2130
}
2231

23-
const { data: domains, error } = await supabase
24-
.from('domains')
25-
.select('*')
26-
.eq('workspace_id', workspace.id);
32+
const domains = workspace.domains;
2733

2834
return (
2935
<div className="p-8">

apps/web/app/app/(dashboard)/[workspaceSlug]/settings/layout.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReactNode } from 'react';
22
import { redirect } from 'next/navigation';
33

4-
import { createAdminClient } from '@saasfy/supabase/server';
4+
import { createAdminClient, getUser } from '@saasfy/supabase/server';
55

66
import { Nav } from './nav';
77

@@ -12,11 +12,18 @@ export default async function SettingsLayout({
1212
children: ReactNode;
1313
params: { workspaceSlug: string };
1414
}) {
15+
const user = await getUser();
16+
17+
if (!user) {
18+
return redirect(`/signin/signin`);
19+
}
20+
1521
const supabase = createAdminClient();
1622

1723
const { data: workspace } = await supabase
1824
.from('workspaces')
19-
.select('*')
25+
.select('*, workspace_users!inner(*)')
26+
.eq('workspace_users.user_id', user.id)
2027
.eq('slug', params.workspaceSlug)
2128
.single();
2229

apps/web/app/app/(dashboard)/[workspaceSlug]/settings/members/page.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { redirect } from 'next/navigation';
44
import { FilterIcon, PlusIcon } from 'lucide-react';
55
import postgres from 'postgres';
66

7-
import { createAdminClient, Tables } from '@saasfy/supabase/server';
7+
import { createAdminClient, getUser, Tables } from '@saasfy/supabase/server';
88
import { Button } from '@saasfy/ui/button';
99
import {
1010
DropdownMenu,
@@ -22,12 +22,19 @@ import { InviteTable } from './invite-table';
2222
import { MemberTable } from './member-table';
2323

2424
export default async function Component({ params }: { params: { workspaceSlug: string } }) {
25+
const user = await getUser();
26+
27+
if (!user) {
28+
return redirect('/login');
29+
}
30+
2531
const supabase = createAdminClient();
2632

2733
const { data: workspace } = await supabase
2834
.from('workspaces')
29-
.select('*')
35+
.select('*, workspace_users!inner(*)')
3036
.eq('slug', params.workspaceSlug)
37+
.eq('workspace_users.user_id', user.id)
3138
.single();
3239

3340
if (!workspace) {

apps/web/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function Settings({ params }: { params: { workspaceSlug: st
2323

2424
const { data: workspace } = await supabase
2525
.from('workspaces')
26-
.select('*, workspace_users(*)')
26+
.select('*, workspace_users!inner(*)')
2727
.eq('slug', params.workspaceSlug)
2828
.eq('workspace_users.user_id', user.id)
2929
.single();

apps/web/app/app/(dashboard)/layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function DashboardLayout({ children }: { children: ReactNod
2020

2121
const { data: workspaces } = await supabase
2222
.from('workspaces')
23-
.select('*, workspace_users(*)')
23+
.select('*, workspace_users!inner(*)')
2424
.eq('workspace_users.user_id', user.id);
2525

2626
return (

apps/web/app/app/(dashboard)/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function Component() {
2020
const supabase = createAdminClient();
2121
const { data: workspaces } = await supabase
2222
.from('workspaces')
23-
.select('*, projects(id), domains(id), workspace_users(id), plans(name)')
23+
.select('*, projects(id), domains(id), workspace_users!inner(id), plans(name)')
2424
.eq('workspace_users.user_id', user.id)
2525
.limit(8);
2626

packages/api/src/lib/with-workspace-user.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function withWorkspaceUser<T>(
2424

2525
const { data: workspace } = await supabase
2626
.from('workspaces')
27-
.select('*, workspace_users(*)')
27+
.select('*, workspace_users!inner(*)')
2828
.eq('slug', params.workspaceSlug)
2929
.eq('workspace_users.user_id', user.id)
3030
.in('workspace_users.role', roles)

packages/components/src/lib/create-project/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function createProject(formData: FormData) {
4646

4747
const { data: workspace } = await supabase
4848
.from('workspaces')
49-
.select('*, workspace_users(*)')
49+
.select('*, workspace_users!inner(*)')
5050
.eq('slug', workspaceSlug)
5151
.eq('workspace_users.user_id', user.id)
5252
.single();

0 commit comments

Comments
 (0)