Skip to content

Commit da22ec6

Browse files
authored
Merge pull request #9659 from Expensify/yuwen-authenticatePusher
Use new AuthenticatePusher NewDot Optimized API commands
2 parents 83f0094 + ae3dc67 commit da22ec6

File tree

7 files changed

+36
-50
lines changed

7 files changed

+36
-50
lines changed

src/libs/Middleware/Logging.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ function Logging(response, request) {
9595
// 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
9696
// it's a sign that the web server is down.
9797
Log.hmmm('[Network] Error: Gateway Timeout error', {message: error.message, status: error.status});
98-
} else if (request.command === 'Push_Authenticate') {
99-
// Push_Authenticate requests can return with fetch errors and no message. It happens because we return a non 200 header like 403 Forbidden.
98+
} else if (request.command === 'AuthenticatePusher') {
99+
// AuthenticatePusher requests can return with fetch errors and no message. It happens because we return a non 200 header like 403 Forbidden.
100100
// 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
101101
// we can get about these requests.
102-
Log.hmmm('[Network] Error: Push_Authenticate', {message: error.message, status: error.status});
102+
Log.hmmm('[Network] Error: AuthenticatePusher', {message: error.message, status: error.status});
103103
} else if (error.message === CONST.ERROR.EXPENSIFY_SERVICE_INTERRUPTED) {
104104
// Expensify site is down completely OR
105105
// 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.

src/libs/Navigation/AppNavigator/AuthScreens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class AuthScreens extends React.Component {
9595
Pusher.init({
9696
appKey: CONFIG.PUSHER.APP_KEY,
9797
cluster: CONFIG.PUSHER.CLUSTER,
98-
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=Push_Authenticate`,
98+
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=AuthenticatePusher`,
9999
}).then(() => {
100100
Report.subscribeToUserEvents();
101101
User.subscribeToUserEvents();

src/libs/Pusher/pusher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function init(args, params) {
5555
// If we want to pass params in our requests to api.php we'll need to add it to socket.config.auth.params
5656
// as per the documentation
5757
// (https://pusher.com/docs/channels/using_channels/connection#channels-options-parameter).
58-
// Any param mentioned here will show up in $_REQUEST when we call "Push_Authenticate". Params passed here need
58+
// Any param mentioned here will show up in $_REQUEST when we call "AuthenticatePusher". Params passed here need
5959
// to pass our inputRules to show up in the request.
6060
if (params) {
6161
socket.config.auth = {};

src/libs/actions/Session/index.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function validateEmail(accountID, validateCode) {
441441
// subscribe to a bunch of channels at once we will only reauthenticate and force reconnect Pusher once.
442442
const reauthenticatePusher = _.throttle(() => {
443443
Log.info('[Pusher] Re-authenticating and then reconnecting');
444-
Authentication.reauthenticate('Push_Authenticate')
444+
Authentication.reauthenticate('AuthenticatePusher')
445445
.then(Pusher.reconnect)
446446
.catch(() => {
447447
console.debug(
@@ -459,39 +459,39 @@ const reauthenticatePusher = _.throttle(() => {
459459
function authenticatePusher(socketID, channelName, callback) {
460460
Log.info('[PusherAuthorizer] Attempting to authorize Pusher', false, {channelName});
461461

462-
DeprecatedAPI.Push_Authenticate({
462+
// We use makeRequestWithSideEffects here because we need to authorize to Pusher (an external service) each time a user connects to any channel.
463+
// eslint-disable-next-line rulesdir/no-api-side-effects-method
464+
API.makeRequestWithSideEffects('AuthenticatePusher', {
463465
socket_id: socketID,
464466
channel_name: channelName,
465467
shouldRetry: false,
466468
forceNetworkRequest: true,
467-
})
468-
.then((response) => {
469-
if (response.jsonCode === CONST.JSON_CODE.NOT_AUTHENTICATED) {
470-
Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher because authToken is expired');
471-
callback(new Error('Pusher failed to authenticate because authToken is expired'), {auth: ''});
469+
}).then((response) => {
470+
if (response.jsonCode === CONST.JSON_CODE.NOT_AUTHENTICATED) {
471+
Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher because authToken is expired');
472+
callback(new Error('Pusher failed to authenticate because authToken is expired'), {auth: ''});
472473

473-
// Attempt to refresh the authToken then reconnect to Pusher
474-
reauthenticatePusher();
475-
return;
476-
}
474+
// Attempt to refresh the authToken then reconnect to Pusher
475+
reauthenticatePusher();
476+
return;
477+
}
477478

478-
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) {
479-
Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher for reason other than expired session');
480-
callback(new Error(`Pusher failed to authenticate because code: ${response.jsonCode} message: ${response.message}`), {auth: ''});
481-
return;
482-
}
479+
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) {
480+
Log.hmmm('[PusherAuthorizer] Unable to authenticate Pusher for reason other than expired session');
481+
callback(new Error(`Pusher failed to authenticate because code: ${response.jsonCode} message: ${response.message}`), {auth: ''});
482+
return;
483+
}
483484

484-
Log.info(
485-
'[PusherAuthorizer] Pusher authenticated successfully',
486-
false,
487-
{channelName},
488-
);
489-
callback(null, response);
490-
})
491-
.catch((error) => {
492-
Log.hmmm('[PusherAuthorizer] Unhandled error: ', {channelName, error});
493-
callback(new Error('Push_Authenticate request failed'), {auth: ''});
494-
});
485+
Log.info(
486+
'[PusherAuthorizer] Pusher authenticated successfully',
487+
false,
488+
{channelName},
489+
);
490+
callback(null, response);
491+
}).catch((error) => {
492+
Log.hmmm('[PusherAuthorizer] Unhandled error: ', {channelName, error});
493+
callback(new Error('AuthenticatePusher request failed'), {auth: ''});
494+
});
495495
}
496496

497497
/**

src/libs/deprecatedAPI.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,6 @@ function PreferredLocale_Update(parameters) {
278278
return Network.post(commandName, parameters);
279279
}
280280

281-
/**
282-
* @param {Object} parameters
283-
* @param {String} parameters.socket_id
284-
* @param {String} parameters.channel_name
285-
* @returns {Promise}
286-
*/
287-
function Push_Authenticate(parameters) {
288-
const commandName = 'Push_Authenticate';
289-
requireParameters(['socket_id', 'channel_name'],
290-
parameters, commandName);
291-
return Network.post(commandName, parameters);
292-
}
293-
294281
/**
295282
* @param {Object} parameters
296283
* @param {Number} parameters.reportID
@@ -936,7 +923,6 @@ export {
936923
PersonalDetails_Update,
937924
Plaid_GetLinkToken,
938925
Policy_Employees_Merge,
939-
Push_Authenticate,
940926
RejectTransaction,
941927
Report_AddComment,
942928
Report_GetHistory,

tests/actions/ReportTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('actions/Report', () => {
3030
Pusher.init({
3131
appKey: CONFIG.PUSHER.APP_KEY,
3232
cluster: CONFIG.PUSHER.CLUSTER,
33-
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=Push_Authenticate`,
33+
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=AuthenticatePusher`,
3434
});
3535

3636
Onyx.init({

tests/unit/NetworkTest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ test('Sequential queue will succeed if triggered while reauthentication via main
643643
})
644644
.then(() => {
645645
// When we queue both non-persistable and persistable commands that will trigger reauthentication and go offline at the same time
646-
Network.post('Push_Authenticate', {content: 'value1'});
646+
Network.post('AuthenticatePusher', {content: 'value1'});
647647
Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});
648648
expect(NetworkStore.isOffline()).toBe(false);
649649
expect(NetworkStore.isAuthenticating()).toBe(false);
@@ -678,9 +678,9 @@ test('Sequential queue will succeed if triggered while reauthentication via main
678678
// We are not offline anymore
679679
expect(NetworkStore.isOffline()).toBe(false);
680680

681-
// First call to xhr is the Push_Authenticate request that could not call Authenticate because we went offline
681+
// First call to xhr is the AuthenticatePusher request that could not call Authenticate because we went offline
682682
const [firstCommand] = xhr.mock.calls[0];
683-
expect(firstCommand).toBe('Push_Authenticate');
683+
expect(firstCommand).toBe('AuthenticatePusher');
684684

685685
// Second call to xhr is the MockCommand that also failed with a 407
686686
const [secondCommand] = xhr.mock.calls[1];

0 commit comments

Comments
 (0)