Skip to content

Commit 4ff39c8

Browse files
committed
Fix redundant flow call and clear params
1 parent ef9ae48 commit 4ff39c8

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

packages/react/src/components/presentation/SignIn/component-driven/SignIn.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
265265
const url = new URL(window.location.href);
266266
url.searchParams.delete('flowId');
267267
url.searchParams.delete('sessionDataKey');
268+
url.searchParams.delete('applicationId');
268269
window?.history?.replaceState({}, '', url.toString());
269270
};
270271

@@ -337,18 +338,6 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
337338
return;
338339
}
339340

340-
// If flowId is in URL or sessionStorage but no active flow state, clean it up
341-
// This handles stale flowIds from previous sessions or incomplete flows
342-
if ((urlParams.flowId || storedFlowId) && !currentFlowId) {
343-
console.warn(
344-
'[SignIn] FlowId in URL/sessionStorage but no active flow state detected. Cleaning up stale flowId.'
345-
);
346-
setFlowId(null);
347-
sessionStorage.removeItem('asgardeo_flow_id');
348-
cleanupFlowUrlParams();
349-
// Continue to initialize with applicationId instead
350-
}
351-
352341
// Only initialize if we're not processing an OAuth callback or submission
353342
const currentUrlParams = getUrlParams();
354343
if (
@@ -365,6 +354,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
365354
initializationAttemptedRef.current = true;
366355
initializeFlow();
367356
}
357+
368358
}, [isInitialized, isLoading, isFlowInitialized, currentFlowId]);
369359

370360
/**

packages/react/src/components/presentation/SignUp/BaseSignUp.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,29 @@ const BaseSignUpContent: FC<BaseSignUpProps> = ({
754754
],
755755
);
756756

757+
/**
758+
* Parse URL parameters to check for OAuth redirect state.
759+
*/
760+
const getUrlParams = () => {
761+
const urlParams = new URL(window?.location?.href ?? '').searchParams;
762+
return {
763+
code: urlParams.get('code'),
764+
state: urlParams.get('state'),
765+
error: urlParams.get('error'),
766+
};
767+
};
768+
757769
// Initialize the flow on component mount
758770
useEffect(() => {
771+
// Skip initialization if we're in an OAuth redirect state
772+
// Only apply this check for AsgardeoV2 platform
773+
if (platform === Platform.AsgardeoV2) {
774+
const urlParams = getUrlParams();
775+
if (urlParams.code || urlParams.state) {
776+
return;
777+
}
778+
}
779+
759780
if (isInitialized && !isFlowInitialized && !initializationAttemptedRef.current) {
760781
initializationAttemptedRef.current = true;
761782

0 commit comments

Comments
 (0)