@@ -26,6 +26,7 @@ import { scrollToTop } from 'src/utilities/ScrollToTop'
2626
2727import { DisclosureInterstitial } from 'src/views/disclosure/Interstitial'
2828import { AnalyticEvents } from 'src/const/Analytics'
29+ import { OauthState } from 'src/const/consts'
2930import useAnalyticsEvent from 'src/hooks/useAnalyticsEvent'
3031import { PostMessageContext } from 'src/ConnectWidget'
3132
@@ -86,13 +87,10 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => {
8687 * Called when we succesfully generate an oauth window uri for the exsting
8788 * member, or use the uri from a brand new member.
8889 */
89- function onStartOAuthSuccess ( member , oauthWindowURI ) {
90+ function onStartOAuthSuccess ( member , oauthWindowURI , memberState ) {
9091 setIsStartingOauth ( false )
9192 setOAuthStartError ( null )
92- dispatch ( {
93- type : connectActions . ActionTypes . START_OAUTH_SUCCESS ,
94- payload : { member, oauthWindowURI } ,
95- } )
93+ dispatch ( connectActions . startOauthSuccess ( member , oauthWindowURI , memberState ) )
9694 }
9795
9896 /**
@@ -120,6 +118,14 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => {
120118 useEffect ( ( ) => {
121119 if ( ! isStartingOauth ) return ( ) => { }
122120
121+ const loadPendingOAuthState = ( memberGuid ) =>
122+ defer ( ( ) =>
123+ api . loadOAuthStates ( {
124+ outbound_member_guid : memberGuid ,
125+ auth_status : OauthState . AuthStatus . PENDING ,
126+ } ) ,
127+ ) . pipe ( map ( ( states ) => states ?. [ 0 ] ) )
128+
123129 let member$
124130
125131 /**
@@ -152,14 +158,25 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => {
152158 config ,
153159 ) ,
154160 )
155- . pipe ( map ( ( resp ) => resp . member ) )
161+ . pipe (
162+ map ( ( resp ) => resp . member ) ,
163+ mergeMap ( ( newMember ) =>
164+ loadPendingOAuthState ( newMember . guid ) . pipe (
165+ map ( ( newMemberState ) => ( {
166+ member : newMember ,
167+ oauthWindowURI : newMember . oauth_window_uri ,
168+ memberState : newMemberState ,
169+ } ) ) ,
170+ ) ,
171+ ) ,
172+ )
156173 . subscribe (
157- ( member ) => {
174+ ( { member, oauthWindowURI , memberState } ) => {
158175 sendAnalyticsEvent ( AnalyticEvents . OAUTH_PENDING_MEMBER_CREATED , {
159176 institution_guid : institution . guid ,
160177 institution_name : institution . name ,
161178 } )
162- onStartOAuthSuccess ( member , member . oauth_window_uri )
179+ onStartOAuthSuccess ( member , oauthWindowURI , memberState )
163180 } ,
164181 ( err ) => onStartOAuthFail ( err ) ,
165182 )
@@ -171,12 +188,25 @@ export const OAuthStep = React.forwardRef((props, navigationRef) => {
171188 . pipe (
172189 mergeMap ( ( existingMember ) =>
173190 defer ( ( ) => api . getOAuthWindowURI ( existingMember . guid , config ) ) . pipe (
174- map ( ( { oauth_window_uri } ) => [ existingMember , oauth_window_uri ] ) ,
191+ map ( ( { oauth_window_uri } ) => ( {
192+ member : existingMember ,
193+ oauthWindowURI : oauth_window_uri ,
194+ } ) ) ,
195+ ) ,
196+ ) ,
197+ mergeMap ( ( { member, oauthWindowURI } ) =>
198+ loadPendingOAuthState ( member . guid ) . pipe (
199+ map ( ( newMemberState ) => ( {
200+ member,
201+ oauthWindowURI,
202+ memberState : newMemberState ,
203+ } ) ) ,
175204 ) ,
176205 ) ,
177206 )
178207 . subscribe (
179- ( [ member , oauthWindowURI ] ) => onStartOAuthSuccess ( member , oauthWindowURI ) ,
208+ ( { member, oauthWindowURI, memberState } ) =>
209+ onStartOAuthSuccess ( member , oauthWindowURI , memberState ) ,
180210 ( err ) => onStartOAuthFail ( err ) ,
181211 )
182212
0 commit comments