Skip to content

Commit

Permalink
Merge pull request #46 from Saasfy/fix-workflow-filtering
Browse files Browse the repository at this point in the history
fix(web): fix workspace access problems
  • Loading branch information
IKatsuba authored May 8, 2024
2 parents baa61a3 + cf8ec3d commit 50910c0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [IKatsuba,Saasfy]
github: [IKatsuba, Saasfy]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/app/(dashboard)/[workspaceSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function Component({ params }: { params: { workspaceSlug: s

const { data: workspace } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.select('*, workspace_users!inner(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import { redirect } from 'next/navigation';

import { ExternalLinkIcon } from 'lucide-react';

import { createAdminClient } from '@saasfy/supabase/server';
import { createAdminClient, getUser } from '@saasfy/supabase/server';
import { Badge } from '@saasfy/ui/badge';

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

export default async function Component({ params }: { params: { workspaceSlug: string } }) {
const user = await getUser();

if (!user) {
return redirect('/login');
}

const supabase = createAdminClient();

const { data: workspace } = await supabase
.from('workspaces')
.select('*')
.select('*, workspace_users!inner(*), domains(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();

if (!workspace) {
return null;
}

const { data: domains, error } = await supabase
.from('domains')
.select('*')
.eq('workspace_id', workspace.id);
const domains = workspace.domains;

return (
<div className="p-8">
Expand Down
11 changes: 9 additions & 2 deletions apps/web/app/app/(dashboard)/[workspaceSlug]/settings/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode } from 'react';
import { redirect } from 'next/navigation';

import { createAdminClient } from '@saasfy/supabase/server';
import { createAdminClient, getUser } from '@saasfy/supabase/server';

import { Nav } from './nav';

Expand All @@ -12,11 +12,18 @@ export default async function SettingsLayout({
children: ReactNode;
params: { workspaceSlug: string };
}) {
const user = await getUser();

if (!user) {
return redirect(`/signin/signin`);
}

const supabase = createAdminClient();

const { data: workspace } = await supabase
.from('workspaces')
.select('*')
.select('*, workspace_users!inner(*)')
.eq('workspace_users.user_id', user.id)
.eq('slug', params.workspaceSlug)
.single();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { redirect } from 'next/navigation';
import { FilterIcon, PlusIcon } from 'lucide-react';
import postgres from 'postgres';

import { createAdminClient, Tables } from '@saasfy/supabase/server';
import { createAdminClient, getUser, Tables } from '@saasfy/supabase/server';
import { Button } from '@saasfy/ui/button';
import {
DropdownMenu,
Expand All @@ -22,12 +22,19 @@ import { InviteTable } from './invite-table';
import { MemberTable } from './member-table';

export default async function Component({ params }: { params: { workspaceSlug: string } }) {
const user = await getUser();

if (!user) {
return redirect('/login');
}

const supabase = createAdminClient();

const { data: workspace } = await supabase
.from('workspaces')
.select('*')
.select('*, workspace_users!inner(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();

if (!workspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function Settings({ params }: { params: { workspaceSlug: st

const { data: workspace } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.select('*, workspace_users!inner(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function DashboardLayout({ children }: { children: ReactNod

const { data: workspaces } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.select('*, workspace_users!inner(*)')
.eq('workspace_users.user_id', user.id);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/app/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function Component() {
const supabase = createAdminClient();
const { data: workspaces } = await supabase
.from('workspaces')
.select('*, projects(id), domains(id), workspace_users(id), plans(name)')
.select('*, projects(id), domains(id), workspace_users!inner(id), plans(name)')
.eq('workspace_users.user_id', user.id)
.limit(8);

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/lib/with-workspace-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function withWorkspaceUser<T>(

const { data: workspace } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.select('*, workspace_users!inner(*)')
.eq('slug', params.workspaceSlug)
.eq('workspace_users.user_id', user.id)
.in('workspace_users.role', roles)
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/lib/create-project/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function createProject(formData: FormData) {

const { data: workspace } = await supabase
.from('workspaces')
.select('*, workspace_users(*)')
.select('*, workspace_users!inner(*)')
.eq('slug', workspaceSlug)
.eq('workspace_users.user_id', user.id)
.single();
Expand Down

0 comments on commit 50910c0

Please sign in to comment.