diff --git a/src/libs/Middleware/Logging.js b/src/libs/Middleware/Logging.js index 45af93e5ef5b..fe63e16291ad 100644 --- a/src/libs/Middleware/Logging.js +++ b/src/libs/Middleware/Logging.js @@ -95,11 +95,11 @@ function Logging(response, request) { // This error seems to only throw on dev when localhost:8080 tries to access the production web server. It's unclear whether this can happen on production or if // it's a sign that the web server is down. Log.hmmm('[Network] Error: Gateway Timeout error', {message: error.message, status: error.status}); - } else if (request.command === 'Push_Authenticate') { - // Push_Authenticate requests can return with fetch errors and no message. It happens because we return a non 200 header like 403 Forbidden. + } else if (request.command === 'AuthenticatePusher') { + // AuthenticatePusher requests can return with fetch errors and no message. It happens because we return a non 200 header like 403 Forbidden. // This is common to see if we are subscribing to a bad channel related to something the user shouldn't be able to access. There's no additional information // we can get about these requests. - Log.hmmm('[Network] Error: Push_Authenticate', {message: error.message, status: error.status}); + Log.hmmm('[Network] Error: AuthenticatePusher', {message: error.message, status: error.status}); } else if (error.message === CONST.ERROR.EXPENSIFY_SERVICE_INTERRUPTED) { // Expensify site is down completely OR // Auth (database connection) is down / bedrock has timed out while making a request. We currently can't tell the difference between Auth down and bedrock timing out. diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 0d40ad9ed839..02340ac16738 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -95,7 +95,7 @@ class AuthScreens extends React.Component { Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, cluster: CONFIG.PUSHER.CLUSTER, - authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=Push_Authenticate`, + authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=AuthenticatePusher`, }).then(() => { Report.subscribeToUserEvents(); User.subscribeToUserEvents(); diff --git a/src/libs/Pusher/pusher.js b/src/libs/Pusher/pusher.js index 600d428f0be8..5fd1e7fa6d26 100644 --- a/src/libs/Pusher/pusher.js +++ b/src/libs/Pusher/pusher.js @@ -55,7 +55,7 @@ function init(args, params) { // If we want to pass params in our requests to api.php we'll need to add it to socket.config.auth.params // as per the documentation // (https://pusher.com/docs/channels/using_channels/connection#channels-options-parameter). - // Any param mentioned here will show up in $_REQUEST when we call "Push_Authenticate". Params passed here need + // Any param mentioned here will show up in $_REQUEST when we call "AuthenticatePusher". Params passed here need // to pass our inputRules to show up in the request. if (params) { socket.config.auth = {}; diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 23e8769ff635..3223a159b223 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -441,7 +441,7 @@ function validateEmail(accountID, validateCode) { // subscribe to a bunch of channels at once we will only reauthenticate and force reconnect Pusher once. const reauthenticatePusher = _.throttle(() => { Log.info('[Pusher] Re-authenticating and then reconnecting'); - Authentication.reauthenticate('Push_Authenticate') + Authentication.reauthenticate('AuthenticatePusher') .then(Pusher.reconnect) .catch(() => { console.debug( @@ -459,39 +459,39 @@ const reauthenticatePusher = _.throttle(() => { function authenticatePusher(socketID, channelName, callback) { Log.info('[PusherAuthorizer] Attempting to authorize Pusher', false, {channelName}); - DeprecatedAPI.Push_Authenticate({ + // We use makeRequestWithSideEffects here because we need to authorize to Pusher (an external service) each time a user connects to any channel. + // eslint-disable-next-line rulesdir/no-api-side-effects-method + API.makeRequestWithSideEffects('AuthenticatePusher', { socket_id: socketID, channel_name: channelName, shouldRetry: false, forceNetworkRequest: true, - }) - .then((response) => { - if (response.jsonCode === CONST.JSON_CODE.NOT_AUTHENTICATED) { - Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher because authToken is expired'); - callback(new Error('Pusher failed to authenticate because authToken is expired'), {auth: ''}); + }).then((response) => { + if (response.jsonCode === CONST.JSON_CODE.NOT_AUTHENTICATED) { + Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher because authToken is expired'); + callback(new Error('Pusher failed to authenticate because authToken is expired'), {auth: ''}); - // Attempt to refresh the authToken then reconnect to Pusher - reauthenticatePusher(); - return; - } + // Attempt to refresh the authToken then reconnect to Pusher + reauthenticatePusher(); + return; + } - if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) { - Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher for reason other than expired session'); - callback(new Error(`Pusher failed to authenticate because code: ${response.jsonCode} message: ${response.message}`), {auth: ''}); - return; - } + if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) { + Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher for reason other than expired session'); + callback(new Error(`Pusher failed to authenticate because code: ${response.jsonCode} message: ${response.message}`), {auth: ''}); + return; + } - Log.info( - '[PusherAuthorizer] Pusher authenticated successfully', - false, - {channelName}, - ); - callback(null, response); - }) - .catch((error) => { - Log.hmmm('[PusherAuthorizer] Unhandled error: ', {channelName, error}); - callback(new Error('Push_Authenticate request failed'), {auth: ''}); - }); + Log.info( + '[PusherAuthorizer] Pusher authenticated successfully', + false, + {channelName}, + ); + callback(null, response); + }).catch((error) => { + Log.hmmm('[PusherAuthorizer] Unhandled error: ', {channelName, error}); + callback(new Error('AuthenticatePusher request failed'), {auth: ''}); + }); } /** diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 24a9c3e9c73c..2f8ab1404e42 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -278,19 +278,6 @@ function PreferredLocale_Update(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {String} parameters.socket_id - * @param {String} parameters.channel_name - * @returns {Promise} - */ -function Push_Authenticate(parameters) { - const commandName = 'Push_Authenticate'; - requireParameters(['socket_id', 'channel_name'], - parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {Number} parameters.reportID @@ -936,7 +923,6 @@ export { PersonalDetails_Update, Plaid_GetLinkToken, Policy_Employees_Merge, - Push_Authenticate, RejectTransaction, Report_AddComment, Report_GetHistory, diff --git a/tests/actions/ReportTest.js b/tests/actions/ReportTest.js index 99c2b0fb0e8e..18ed248f4281 100644 --- a/tests/actions/ReportTest.js +++ b/tests/actions/ReportTest.js @@ -30,7 +30,7 @@ describe('actions/Report', () => { Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, cluster: CONFIG.PUSHER.CLUSTER, - authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=Push_Authenticate`, + authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=AuthenticatePusher`, }); Onyx.init({ diff --git a/tests/unit/NetworkTest.js b/tests/unit/NetworkTest.js index cd7ee2dc3caa..b09b23d49645 100644 --- a/tests/unit/NetworkTest.js +++ b/tests/unit/NetworkTest.js @@ -643,7 +643,7 @@ test('Sequential queue will succeed if triggered while reauthentication via main }) .then(() => { // When we queue both non-persistable and persistable commands that will trigger reauthentication and go offline at the same time - Network.post('Push_Authenticate', {content: 'value1'}); + Network.post('AuthenticatePusher', {content: 'value1'}); Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); expect(NetworkStore.isOffline()).toBe(false); expect(NetworkStore.isAuthenticating()).toBe(false); @@ -678,9 +678,9 @@ test('Sequential queue will succeed if triggered while reauthentication via main // We are not offline anymore expect(NetworkStore.isOffline()).toBe(false); - // First call to xhr is the Push_Authenticate request that could not call Authenticate because we went offline + // First call to xhr is the AuthenticatePusher request that could not call Authenticate because we went offline const [firstCommand] = xhr.mock.calls[0]; - expect(firstCommand).toBe('Push_Authenticate'); + expect(firstCommand).toBe('AuthenticatePusher'); // Second call to xhr is the MockCommand that also failed with a 407 const [secondCommand] = xhr.mock.calls[1];