@@ -62,55 +62,44 @@ function reauthenticate(command = ''): Promise<void> {
62
62
partnerPassword : CONFIG . EXPENSIFY . PARTNER_PASSWORD ,
63
63
partnerUserID : credentials ?. autoGeneratedLogin ,
64
64
partnerUserSecret : credentials ?. autoGeneratedPassword ,
65
- } )
66
- . then ( ( response ) => {
67
- if ( response . jsonCode === CONST . JSON_CODE . UNABLE_TO_RETRY ) {
68
- // If authentication fails, then the network can be unpaused
69
- NetworkStore . setIsAuthenticating ( false ) ;
65
+ } ) . then ( ( response ) => {
66
+ if ( response . jsonCode === CONST . JSON_CODE . UNABLE_TO_RETRY ) {
67
+ // When a fetch() fails due to a network issue and an error is thrown we won't log the user out. Most likely they
68
+ // have a spotty connection and will need to retry reauthenticate when they come back online. Error so it can be handled by the retry mechanism.
69
+ throw new Error ( 'Unable to retry Authenticate request' ) ;
70
+ }
70
71
71
- // When a fetch() fails due to a network issue and an error is thrown we won't log the user out. Most likely they
72
- // have a spotty connection and will need to try to reauthenticate when they come back online. We will error so it
73
- // can be handled by callers of reauthenticate().
74
- throw new Error ( 'Unable to retry Authenticate request' ) ;
75
- }
76
-
77
- // If authentication fails and we are online then log the user out
78
- if ( response . jsonCode !== 200 ) {
79
- const errorMessage = ErrorUtils . getAuthenticateErrorMessage ( response ) ;
80
- NetworkStore . setIsAuthenticating ( false ) ;
81
- Log . hmmm ( 'Redirecting to Sign In because we failed to reauthenticate' , {
82
- command,
83
- error : errorMessage ,
84
- } ) ;
85
- redirectToSignIn ( errorMessage ) ;
86
- return ;
87
- }
72
+ // If authentication fails and we are online then log the user out
73
+ if ( response . jsonCode !== 200 ) {
74
+ const errorMessage = ErrorUtils . getAuthenticateErrorMessage ( response ) ;
75
+ NetworkStore . setIsAuthenticating ( false ) ;
76
+ Log . hmmm ( 'Redirecting to Sign In because we failed to reauthenticate' , {
77
+ command,
78
+ error : errorMessage ,
79
+ } ) ;
80
+ redirectToSignIn ( errorMessage ) ;
81
+ return ;
82
+ }
88
83
89
- // If we reauthenticated due to an expired delegate token, restore the delegate's original account.
90
- // This is because the credentials used to reauthenticate were for the delegate's original account, and not for the account they were connected as.
91
- if ( Delegate . isConnectedAsDelegate ( ) ) {
92
- Log . info ( 'Reauthenticated while connected as a delegate. Restoring original account.' ) ;
93
- Delegate . restoreDelegateSession ( response ) ;
94
- return ;
95
- }
84
+ // If we reauthenticated due to an expired delegate token, restore the delegate's original account.
85
+ // This is because the credentials used to reauthenticate were for the delegate's original account, and not for the account they were connected as.
86
+ if ( Delegate . isConnectedAsDelegate ( ) ) {
87
+ Log . info ( 'Reauthenticated while connected as a delegate. Restoring original account.' ) ;
88
+ Delegate . restoreDelegateSession ( response ) ;
89
+ return ;
90
+ }
96
91
97
- // Update authToken in Onyx and in our local variables so that API requests will use the new authToken
98
- updateSessionAuthTokens ( response . authToken , response . encryptedAuthToken ) ;
92
+ // Update authToken in Onyx and in our local variables so that API requests will use the new authToken
93
+ updateSessionAuthTokens ( response . authToken , response . encryptedAuthToken ) ;
99
94
100
- // Note: It is important to manually set the authToken that is in the store here since any requests that are hooked into
101
- // reauthenticate .then() will immediate post and use the local authToken. Onyx updates subscribers lately so it is not
102
- // enough to do the updateSessionAuthTokens() call above.
103
- NetworkStore . setAuthToken ( response . authToken ?? null ) ;
95
+ // Note: It is important to manually set the authToken that is in the store here since any requests that are hooked into
96
+ // reauthenticate .then() will immediate post and use the local authToken. Onyx updates subscribers lately so it is not
97
+ // enough to do the updateSessionAuthTokens() call above.
98
+ NetworkStore . setAuthToken ( response . authToken ?? null ) ;
104
99
105
- // The authentication process is finished so the network can be unpaused to continue processing requests
106
- NetworkStore . setIsAuthenticating ( false ) ;
107
- } )
108
- . catch ( ( error ) => {
109
- // In case the authenticate call throws error, we need to sign user out as most likely they are missing credentials
110
- NetworkStore . setIsAuthenticating ( false ) ;
111
- Log . hmmm ( 'Redirecting to Sign In because we failed to reauthenticate' , { error} ) ;
112
- redirectToSignIn ( 'passwordForm.error.fallback' ) ;
113
- } ) ;
100
+ // The authentication process is finished so the network can be unpaused to continue processing requests
101
+ NetworkStore . setIsAuthenticating ( false ) ;
102
+ } ) ;
114
103
}
115
104
116
105
export { reauthenticate , Authenticate } ;
0 commit comments