Skip to content

Commit 465ab00

Browse files
committed
disallow member page access to non-associated organizations
1 parent 7ac7872 commit 465ab00

File tree

1 file changed

+10
-1
lines changed
  • src/app/organizations/[id]/members

1 file changed

+10
-1
lines changed

src/app/organizations/[id]/members/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"use client";
22

33
import { use, useEffect, useState } from "react";
4-
import { useSearchParams } from "next/navigation";
4+
import { useSearchParams, redirect } from "next/navigation";
55
import { Card, CardContent } from "@/components/ui/card";
66
import { useAuthStore } from "@/lib/providers/auth-store-provider";
77
import { useCoachingRelationshipList } from "@/lib/api/coaching-relationships";
88
import { useUserList } from "@/lib/api/organizations/users";
99
import { useCurrentOrganization } from "@/lib/hooks/use-current-organization";
10+
import { useCurrentUserRole } from "@/lib/hooks/use-current-user-role";
1011
import { Id } from "@/types/general";
1112
import { MemberContainer } from "@/components/ui/members/member-container";
1213
import { PageContainer } from "@/components/ui/page-container";
14+
import { toast } from "sonner";
1315

1416
export default function MembersPage({
1517
params,
@@ -23,6 +25,7 @@ export default function MembersPage({
2325

2426
const organizationId = use(params).id;
2527
const { currentOrganizationId, setCurrentOrganizationId } = useCurrentOrganization();
28+
const currentUserRoleState = useCurrentUserRole();
2629

2730
useEffect(() => {
2831
// Only sync if different to prevent conflicts with OrganizationSwitcher
@@ -31,6 +34,12 @@ export default function MembersPage({
3134
}
3235
}, [organizationId, currentOrganizationId, setCurrentOrganizationId]);
3336

37+
// Access control: redirect if user doesn't have access to this organization
38+
if (currentOrganizationId === organizationId && currentUserRoleState.status === 'no_access') {
39+
toast.error("You don't have access to this organization");
40+
redirect('/dashboard');
41+
}
42+
3443
const {
3544
relationships,
3645
isLoading: isRelationshipsLoading,

0 commit comments

Comments
 (0)