Skip to content

Commit 560abda

Browse files
committed
feat: Add SCIM2 API functions for organization and user profile management; implement user profile update and retrieval actions
1 parent a446ff0 commit 560abda

29 files changed

+212
-49
lines changed

packages/javascript/src/api/scim2/createOrganization.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/getAllOrganizations.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/getMeOrganizations.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/getOrganization.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/getSchemas.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/index.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/updateMeProfile.ts

Whitespace-only changes.

packages/javascript/src/api/scim2/updateOrganization.ts

Whitespace-only changes.

packages/nextjs/src/AsgardeoNextClient.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
flattenUserSchema,
3838
getScim2Me,
3939
getSchemas,
40+
generateFlattenedUserProfile,
41+
updateMeProfile,
4042
} from '@asgardeo/node';
4143
import {NextRequest, NextResponse} from 'next/server';
4244
import {AsgardeoNextConfig} from './models/config';
@@ -152,11 +154,70 @@ class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> exte
152154
}
153155
}
154156

155-
override async getOrganizations(): Promise<Organization[]> {
156-
throw new Error('Method not implemented.');
157+
override async getUserProfile(userId?: string): Promise<UserProfile> {
158+
await this.ensureInitialized();
159+
160+
try {
161+
const configData = await this.asgardeo.getConfigData();
162+
const baseUrl = configData?.baseUrl;
163+
164+
const profile = await getScim2Me({
165+
baseUrl,
166+
headers: {
167+
Authorization: `Bearer ${await this.getAccessToken(userId)}`,
168+
},
169+
});
170+
171+
const schemas = await getSchemas({
172+
baseUrl,
173+
headers: {
174+
Authorization: `Bearer ${await this.getAccessToken(userId)}`,
175+
},
176+
});
177+
178+
const processedSchemas = flattenUserSchema(schemas);
179+
180+
const output = {
181+
schemas: processedSchemas,
182+
flattenedProfile: generateFlattenedUserProfile(profile, processedSchemas),
183+
profile,
184+
};
185+
186+
return output;
187+
} catch (error) {
188+
return {
189+
schemas: [],
190+
flattenedProfile: await this.asgardeo.getDecodedIdToken(),
191+
profile: await this.asgardeo.getDecodedIdToken(),
192+
};
193+
}
157194
}
158195

159-
override getUserProfile(): Promise<UserProfile> {
196+
async updateUserProfile(payload: any, userId?: string) {
197+
await this.ensureInitialized();
198+
199+
try {
200+
const configData = await this.asgardeo.getConfigData();
201+
const baseUrl = configData?.baseUrl;
202+
203+
return await updateMeProfile({
204+
baseUrl,
205+
payload,
206+
headers: {
207+
Authorization: `Bearer ${await this.getAccessToken(userId)}`,
208+
},
209+
});
210+
} catch (error) {
211+
throw new AsgardeoRuntimeError(
212+
`Failed to update user profile: ${error instanceof Error ? error.message : 'Unknown error'}`,
213+
'AsgardeoNextClient-UpdateProfileError-001',
214+
'react',
215+
'An error occurred while updating the user profile. Please check your configuration and network connection.',
216+
);
217+
}
218+
}
219+
220+
override async getOrganizations(): Promise<Organization[]> {
160221
throw new Error('Method not implemented.');
161222
}
162223

packages/nextjs/src/client/components/presentation/UserDropdown/UserDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const UserDropdown: FC<UserDropdownProps> = ({
125125

126126
const handleSignOut = () => {
127127
signOut();
128-
onSignOut();
128+
onSignOut && onSignOut();
129129
};
130130

131131
const closeProfile = () => {
@@ -135,7 +135,7 @@ const UserDropdown: FC<UserDropdownProps> = ({
135135
// Prepare render props data
136136
const renderProps: UserDropdownRenderProps = {
137137
user,
138-
isLoading,
138+
isLoading: isLoading as boolean,
139139
openProfile: handleManageProfile,
140140
signOut: handleSignOut,
141141
isProfileOpen,

0 commit comments

Comments
 (0)