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