Skip to content

Commit db06041

Browse files
Add instance ID support for multi-instance functionality in Asgardeo components
1 parent ddd4d02 commit db06041

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

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 = await getScim2Me({baseUrl});
193-
const schemas = await getSchemas({baseUrl});
192+
const profile = await getScim2Me({baseUrl, instanceId: this._instanceId});
193+
const schemas = await getSchemas({baseUrl, instanceId: this._instanceId});
194194

195195
const processedSchemas = flattenUserSchema(schemas);
196196

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

223-
return getMeOrganizations({baseUrl});
223+
return getMeOrganizations({baseUrl, instanceId: this._instanceId});
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 getAllOrganizations({baseUrl});
245+
return getAllOrganizations({baseUrl, instanceId: this._instanceId});
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
@@ -141,7 +141,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
141141
errorFallback = <div>Failed to load organization data</div>,
142142
...rest
143143
}: OrganizationProfileProps): ReactElement => {
144-
const {baseUrl} = useAsgardeo();
144+
const {baseUrl, instanceId} = useAsgardeo();
145145
const {t} = useTranslation();
146146
const [organization, setOrganization] = useState<OrganizationDetails | null>(null);
147147
const [loading, setLoading] = useState<boolean>(true);
@@ -160,6 +160,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
160160
const orgData = await getOrganization({
161161
baseUrl,
162162
organizationId,
163+
instanceId,
163164
});
164165
setOrganization(orgData);
165166
} catch (err) {
@@ -186,6 +187,7 @@ const OrganizationProfile: FC<OrganizationProfileProps> = ({
186187
baseUrl,
187188
organizationId,
188189
operations,
190+
instanceId,
189191
});
190192
// Refetch organization data after update
191193
await fetchOrganization();

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

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

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

7676
try {
77-
const response: User = await updateMeProfile({baseUrl, payload});
77+
const response: User = await updateMeProfile({baseUrl, payload, instanceId});
7878
onUpdateProfile(response);
7979
} catch (error: unknown) {
8080
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
* @returns Promise resolving to boolean indicating success.
147147
*/
148148
reInitialize: (config: Partial<AsgardeoReactConfig>) => Promise<boolean>;
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
switchOrganization: null,
183187
reInitialize: null,
184188
platform: undefined,
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
@@ -586,6 +586,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
586586
syncSession,
587587
platform: config?.platform,
588588
switchOrganization,
589+
instanceId,
589590
}),
590591
[
591592
applicationId,
@@ -614,6 +615,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
614615
signUp,
615616
clearSession,
616617
reInitialize,
618+
instanceId,
617619
],
618620
);
619621

0 commit comments

Comments
 (0)