Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/nextjs/src/AsgardeoNextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> exte
return this.asgardeo.getDecodedIdToken(sessionId as string, idToken);
}

async getIdToken(sessionId?: string): Promise<string> {
await this.ensureInitialized();
const resolvedSessionId: string = sessionId || ((await getSessionId()) as string);
return this.asgardeo.getIdToken(resolvedSessionId);
}

override getConfiguration(): T {
return this.asgardeo.getConfigData() as unknown as T;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'use client';

import {AsgardeoContextProps as AsgardeoReactContextProps} from '@asgardeo/react';
import {EmbeddedFlowExecuteRequestConfig, EmbeddedSignInFlowHandleRequestPayload, User} from '@asgardeo/node';
import {EmbeddedFlowExecuteRequestConfig, EmbeddedSignInFlowHandleRequestPayload, User, TokenExchangeRequestConfig, TokenResponse, IdToken} from '@asgardeo/node';
import {Context, createContext} from 'react';

/**
Expand All @@ -44,6 +44,10 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
signOut: () => Promise.resolve({} as any),
signUp: () => Promise.resolve({} as any),
user: null,
getDecodedIdToken: async (sessionId?:string) => Promise.resolve({} as IdToken),
getIdToken: async (sessionId?:string) => Promise.resolve(''),
getAccessToken: async (sessionId?:string) => Promise.resolve(''),
exchangeToken: async (config: TokenExchangeRequestConfig, sessionId?:string) => Promise.resolve({} as TokenResponse | Response),
});

AsgardeoContext.displayName = 'AsgardeoContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export type AsgardeoClientProviderProps = Partial<Omit<AsgardeoProviderProps, 'b
) => Promise<{data: {user: User}; error: string; success: boolean}>;
user: User | null;
userProfile: UserProfile;
getIdToken: AsgardeoContextProps['getIdToken'];
getDecodedIdToken: AsgardeoContextProps['getDecodedIdToken'];
getAccessToken: AsgardeoContextProps['getAccessToken'];
exchangeToken: AsgardeoContextProps['exchangeToken'];
};

const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>> = ({
Expand All @@ -102,6 +106,10 @@ const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>
getAllOrganizations,
switchOrganization,
brandingPreference,
getIdToken,
getDecodedIdToken,
getAccessToken,
exchangeToken,
}: PropsWithChildren<AsgardeoClientProviderProps>) => {
const reRenderCheckRef: RefObject<boolean> = useRef(false);
const router = useRouter();
Expand Down Expand Up @@ -309,8 +317,12 @@ const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>
signUpUrl,
applicationId,
organizationHandle,
getIdToken,
getDecodedIdToken,
getAccessToken,
exchangeToken,
}),
[baseUrl, user, isSignedIn, isLoading, signInUrl, signUpUrl, applicationId, organizationHandle],
[baseUrl, user, isSignedIn, isLoading, signInUrl, signUpUrl, applicationId, organizationHandle, getIdToken, getDecodedIdToken, getAccessToken, exchangeToken],
);

const handleProfileUpdate = (payload: User): void => {
Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/src/server/AsgardeoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ const AsgardeoServerProvider: FC<PropsWithChildren<AsgardeoServerProviderProps>>
switchOrganization={switchOrganization}
brandingPreference={brandingPreference}
createOrganization={createOrganization}
getDecodedIdToken={async () => await asgardeoClient.getDecodedIdToken(sessionId)}
getIdToken={async () => await asgardeoClient.getIdToken(sessionId)}
getAccessToken={async () => await asgardeoClient.getAccessToken(sessionId)}
exchangeToken={async (config) => await asgardeoClient.exchangeToken(config, sessionId)}
>
{children}
</AsgardeoClientProvider>
Expand Down
Loading