Skip to content

Commit

Permalink
Fix migration and NABs
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Jun 17, 2021
1 parent 859726d commit e830882
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/libs/addEncryptedAuthTokenToURL.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import lodashGet from 'lodash/get';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../ONYXKEYS';

let encryptedAuthToken = '';
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: session => encryptedAuthToken = session.encryptedAuthToken,
callback: session => encryptedAuthToken = lodashGet(session, 'encryptedAuthToken', ''),
});

/**
* Add authToken to this attachment URL if necessary
* Add encryptedAuthToken to this attachment URL if necessary
*
* @param {String} url
* @returns {String}
Expand Down
11 changes: 5 additions & 6 deletions src/libs/migrations/AddEncryptedAuthToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import Onyx from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';
import {reauthenticate} from '../API';

const reauthenticateThrottled = _.throttle(reauthenticate, 5000);

/**
* This migration adds an encryptedAuthToken to the SESSION key, if it is not present.
*
Expand All @@ -18,20 +16,21 @@ export default function () {
Onyx.disconnect(connectionID);

if (session && !_.isEmpty(session.encryptedAuthToken)) {
console.debug('[Onyx Migration] Skipped migration AddEncryptedAuthToken');
console.debug('[Migrate Onyx] Skipped migration AddEncryptedAuthToken');
return resolve();
}

if (!session || !session.authToken) {
console.debug('[Onyx Migration] Skipped migration AddEncryptedAuthToken');
console.debug('[Migrate Onyx] Skipped migration AddEncryptedAuthToken');
return resolve();
}

// If there is an auth token but no encrypted auth token, reauthenticate.
if (session.authToken && _.isUndefined(session.encryptedAuthToken)) {
return reauthenticateThrottled('Onyx_Migration_AddEncryptedAuthToken')
return reauthenticate('Onyx_Migration_AddEncryptedAuthToken')
.then(() => {
console.debug('[Onyx Migration] Ran migration AddEncryptedAuthToken');
console.debug('[Migrate Onyx] Ran migration AddEncryptedAuthToken');
resolve();
});
}

Expand Down

0 comments on commit e830882

Please sign in to comment.