1
- import { useClerk , useSession , useUser } from '@clerk/shared/react' ;
2
- import { useState } from 'react' ;
1
+ import { useClerk , useSession , useUserContext } from '@clerk/shared/react' ;
2
+ import { useEffect , useState } from 'react' ;
3
3
4
4
import { useSignOutContext , withCoreSessionSwitchGuard } from '@/ui/contexts' ;
5
5
import { descriptors , Flex , Flow , localizationKeys , Spinner } from '@/ui/customizables' ;
@@ -14,7 +14,7 @@ import { CreateOrganizationScreen } from './CreateOrganizationScreen';
14
14
15
15
const TaskChooseOrganizationInternal = ( ) => {
16
16
const { signOut } = useClerk ( ) ;
17
- const { user } = useUser ( ) ;
17
+ const user = useUserContext ( ) ;
18
18
const { session } = useSession ( ) ;
19
19
const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView ( ) ;
20
20
const { otherSessions } = useMultipleSessions ( { user } ) ;
@@ -32,6 +32,17 @@ const TaskChooseOrganizationInternal = () => {
32
32
const hasExistingResources = ! ! ( userMemberships ?. count || userInvitations ?. count || userSuggestions ?. count ) ;
33
33
const identifier = user ?. primaryEmailAddress ?. emailAddress ?? user ?. username ;
34
34
35
+ // Revalidates organization memberships from client piggybacking
36
+ // TODO (ORGS-784): Introduce architecture to invalidate SWR queries based on client piggybacking
37
+ const hasUpdatedOnClient = user ?. organizationMemberships ?. length !== userMemberships . count ;
38
+ useEffect ( ( ) => {
39
+ if ( ! hasUpdatedOnClient ) {
40
+ return ;
41
+ }
42
+
43
+ void userMemberships ?. revalidate ?.( ) ;
44
+ } , [ hasUpdatedOnClient , userMemberships ] ) ;
45
+
35
46
return (
36
47
< Flow . Root flow = 'taskChooseOrganization' >
37
48
< Card . Root >
0 commit comments