Skip to content

Commit 61618f5

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 23ac8a9 commit 61618f5

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

packages/react/src/AsgardeoReactClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
160160
});
161161
}
162162

163+
async getIdToken(): Promise<string> {
164+
return this.withLoading(async () => {
165+
return this.asgardeo.getIdToken();
166+
});
167+
}
168+
163169
async getUserProfile(options?: any): Promise<UserProfile> {
164170
return this.withLoading(async () => {
165171
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
519519
reInitialize: asgardeo.reInitialize.bind(asgardeo),
520520
signInOptions,
521521
getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
522+
getIdToken: asgardeo.getIdToken.bind(asgardeo),
522523
exchangeToken: asgardeo.exchangeToken.bind(asgardeo),
523524
syncSession,
524525
platform: config?.platform,

0 commit comments

Comments
 (0)