diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 1cde31b65674..23e8769ff635 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; import _ from 'underscore'; +import lodashGet from 'lodash/get'; import ONYXKEYS from '../../../ONYXKEYS'; import redirectToSignIn from '../SignInRedirect'; import * as DeprecatedAPI from '../../deprecatedAPI'; @@ -21,6 +22,8 @@ import * as ValidationUtils from '../../ValidationUtils'; import * as Authentication from '../../Authentication'; import * as ErrorUtils from '../../ErrorUtils'; import * as Welcome from '../Welcome'; +import * as API from '../../API'; +import * as NetworkStore from '../../Network/NetworkStore'; let credentials = {}; Onyx.connect({ @@ -72,24 +75,28 @@ function createAccount(login) { */ function signOut() { Log.info('Flushing logs before signing out', true, {}, true); - if (credentials && credentials.autoGeneratedLogin) { - // Clean up the login that we created - DeprecatedAPI.DeleteLogin({ - partnerUserID: credentials.autoGeneratedLogin, - partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, - partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, - shouldRetry: false, - }) - .then((response) => { - if (response.jsonCode === CONST.JSON_CODE.SUCCESS) { - return; - } - Onyx.merge(ONYXKEYS.SESSION, {error: response.message}); - }); - } - Onyx.set(ONYXKEYS.SESSION, null); - Onyx.set(ONYXKEYS.CREDENTIALS, null); + const optimisticData = [ + { + onyxMethod: 'set', + key: ONYXKEYS.SESSION, + value: null, + }, + { + onyxMethod: 'set', + key: ONYXKEYS.CREDENTIALS, + value: null, + }, + ]; + API.write('LogOut', { + // Send current authToken because we will immediately clear it once triggering this command + authToken: NetworkStore.getAuthToken(), + partnerUserID: lodashGet(credentials, 'autoGeneratedLogin', ''), + partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, + partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, + shouldRetry: false, + }, {optimisticData}); + Timing.clearData(); }