Skip to content

Commit d8e1b6d

Browse files
Merge pull request #265 from thiva-k/add-code-redirect
2 parents e05e047 + 932126a commit d8e1b6d

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

.changeset/tough-ads-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@asgardeo/react': patch
3+
---
4+
5+
Handle code exchange for V2

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,28 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
156156

157157
const isV2Platform = config.platform === Platform.AsgardeoV2;
158158

159-
if (hasAuthParamsResult && !isV2Platform) {
159+
if (hasAuthParamsResult) {
160160
try {
161-
await signIn(
162-
{callOnlyOnRedirect: true},
163-
// authParams?.authorizationCode,
164-
// authParams?.sessionState,
165-
// authParams?.state,
166-
);
161+
if (isV2Platform) {
162+
// For V2 platform, check if this is an embedded flow or traditional OAuth
163+
const urlParams = currentUrl.searchParams;
164+
const code = urlParams.get('code');
165+
const flowIdFromUrl = urlParams.get('flowId');
166+
const storedFlowId = sessionStorage.getItem('asgardeo_flow_id');
167+
168+
// If there's a code and no flowId, exchange OAuth code for tokens
169+
if (code && !flowIdFromUrl && !storedFlowId) {
170+
await signIn();
171+
}
172+
} else {
173+
// If non-V2 platform, use traditional OAuth callback handling
174+
await signIn(
175+
{callOnlyOnRedirect: true},
176+
// authParams?.authorizationCode,
177+
// authParams?.sessionState,
178+
// authParams?.state,
179+
);
180+
}
167181
// setError(null);
168182
} catch (error) {
169183
if (error && Object.prototype.hasOwnProperty.call(error, 'code')) {

0 commit comments

Comments
 (0)