Skip to content

Commit 2af8495

Browse files
Add instance ID support for multi-instance functionality in Asgardeo components
1 parent 29262a6 commit 2af8495

6 files changed

Lines changed: 18 additions & 8 deletions

File tree

packages/react/src/AsgardeoReactClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
189189
baseUrl = configData?.baseUrl;
190190
}
191191

192-
const profile: User = await getScim2Me({baseUrl});
193-
const schemas: any = await getSchemas({baseUrl});
192+
const profile: User = await getScim2Me({baseUrl, instanceId: this.getInstanceId()});
193+
const schemas: any = await getSchemas({baseUrl, instanceId: this.getInstanceId()});
194194

195195
const processedSchemas: any = flattenUserSchema(schemas);
196196

@@ -220,7 +220,7 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
220220
baseUrl = configData?.baseUrl;
221221
}
222222

223-
return await getMeOrganizations({baseUrl});
223+
return await getMeOrganizations({baseUrl, instanceId: this.getInstanceId()});
224224
} catch (error) {
225225
throw new AsgardeoRuntimeError(
226226
`Failed to fetch the user's associated organizations: ${
@@ -242,7 +242,7 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
242242
baseUrl = configData?.baseUrl;
243243
}
244244

245-
return await getAllOrganizations({baseUrl});
245+
return await getAllOrganizations({baseUrl, instanceId: this.getInstanceId()});
246246
} catch (error) {
247247
throw new AsgardeoRuntimeError(
248248
`Failed to fetch all organizations: ${error instanceof Error ? error.message : String(error)}`,

packages/react/src/components/presentation/CreateOrganization/CreateOrganization.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const CreateOrganization: FC<CreateOrganizationProps> = ({
7676
defaultParentId,
7777
...props
7878
}: CreateOrganizationProps): ReactElement => {
79-
const {isSignedIn, baseUrl} = useAsgardeo();
79+
const {isSignedIn, baseUrl, instanceId} = useAsgardeo();
8080
const {currentOrganization, revalidateMyOrganizations} = useOrganization();
8181
const [loading, setLoading] = useState(false);
8282
const [error, setError] = useState<string | null>(null);
@@ -112,6 +112,7 @@ export const CreateOrganization: FC<CreateOrganizationProps> = ({
112112
...payload,
113113
parentId,
114114
},
115+
instanceId,
115116
});
116117
}
117118

packages/react/src/components/presentation/OrganizationProfile/OrganizationProfile.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
146146
errorFallback,
147147
...rest
148148
}: OrganizationProfileProps): ReactElement => {
149-
const {baseUrl} = useAsgardeo();
149+
const {baseUrl, instanceId} = useAsgardeo();
150150
const {t} = useTranslation();
151151
const [organization, setOrganization] = useState<OrganizationDetails | null>(null);
152152

@@ -159,6 +159,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
159159
const orgData: any = await getOrganization({
160160
baseUrl,
161161
organizationId,
162+
instanceId,
162163
});
163164
setOrganization(orgData);
164165
} catch (err) {
@@ -182,6 +183,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
182183
baseUrl,
183184
operations,
184185
organizationId,
186+
instanceId,
185187
});
186188
// Refetch organization data after update
187189
await fetchOrganization();

packages/react/src/components/presentation/UserProfile/UserProfile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export type UserProfileProps = Omit<BaseUserProfileProps, 'user' | 'profile' | '
6565
* ```
6666
*/
6767
const UserProfile: FC<UserProfileProps> = ({...rest}: UserProfileProps): ReactElement => {
68-
const {baseUrl} = useAsgardeo();
68+
const {baseUrl, instanceId} = useAsgardeo();
6969
const {profile, flattenedProfile, schemas, onUpdateProfile} = useUser();
7070
const {t} = useTranslation();
7171

@@ -75,7 +75,7 @@ const UserProfile: FC<UserProfileProps> = ({...rest}: UserProfileProps): ReactEl
7575
setError(null);
7676

7777
try {
78-
const response: User = await updateMeProfile({baseUrl, payload});
78+
const response: User = await updateMeProfile({baseUrl, payload, instanceId});
7979
onUpdateProfile(response);
8080
} catch (caughtError: unknown) {
8181
let message: string = t('user.profile.update.generic.error');

packages/react/src/contexts/Asgardeo/AsgardeoContext.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export type AsgardeoContextProps = {
146146
signUpUrl: string | undefined;
147147

148148
user: any;
149+
/**
150+
* Instance ID for multi-instance support.
151+
*/
152+
instanceId: number;
149153
} & Pick<AsgardeoReactConfig, 'storage' | 'platform'> &
150154
Pick<AsgardeoReactClient, 'clearSession' | 'switchOrganization'>;
151155

@@ -182,6 +186,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
182186
storage: 'sessionStorage',
183187
switchOrganization: null,
184188
user: null,
189+
instanceId: 0,
185190
});
186191

187192
AsgardeoContext.displayName = 'AsgardeoContext';

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
587587
switchOrganization,
588588
syncSession,
589589
user,
590+
instanceId,
590591
}),
591592
[
592593
applicationId,
@@ -615,6 +616,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
615616
signUp,
616617
clearSession,
617618
reInitialize,
619+
instanceId,
618620
],
619621
);
620622

0 commit comments

Comments
 (0)