File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed
packages/react/src/contexts/Asgardeo Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @asgardeo/react ' : patch
3+ ---
4+
5+ Handle code exchange for V2
Original file line number Diff line number Diff 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' ) ) {
You can’t perform that action at this time.
0 commit comments