Skip to content

Commit c9c0486

Browse files
committed
feat(react): expose getIdToken API
this commit expose the getIdToken from the AsgardeoContext so it can be accessed via useAsgardeo
1 parent ff997e0 commit c9c0486

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/react/src/AsgardeoReactClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
158158
return this.asgardeo.getDecodedIdToken(sessionId);
159159
}
160160

161+
async getIdToken(): Promise<string> {
162+
return this.withLoading(async () => {
163+
return this.asgardeo.getIdToken();
164+
});
165+
}
166+
161167
async getUserProfile(options?: any): Promise<UserProfile> {
162168
return this.withLoading(async () => {
163169
try {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ export type AsgardeoContextProps = {
113113
*/
114114
getDecodedIdToken: () => Promise<IdToken>;
115115

116+
/**
117+
* Function to retrieve the ID token.
118+
* This function retrieves the ID token and returns it.
119+
*
120+
* @returns A promise that resolves to the ID token.
121+
*/
122+
getIdToken: () => Promise<string>;
123+
116124
/**
117125
* Retrieves the access token stored in the storage.
118126
* This function retrieves the access token and returns it.
@@ -167,6 +175,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
167175
},
168176
signInOptions: {},
169177
getDecodedIdToken: null,
178+
getIdToken: null,
170179
getAccessToken: null,
171180
exchangeToken: null,
172181
storage: 'sessionStorage',

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
497497
return await asgardeo.getDecodedIdToken();
498498
}, [asgardeo]);
499499

500+
const getIdToken = useCallback(async (): Promise<string> => {
501+
return await asgardeo.getIdToken();
502+
}, [asgardeo]);
503+
500504
const getAccessToken = useCallback(async (): Promise<string> => {
501505
return await asgardeo.getAccessToken();
502506
}, [asgardeo]);
@@ -576,6 +580,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
576580
reInitialize,
577581
signInOptions,
578582
getDecodedIdToken,
583+
getIdToken,
579584
exchangeToken,
580585
syncSession,
581586
platform: config?.platform,

0 commit comments

Comments
 (0)