From 14d9d155bbdd3b66780349f9e55a18ac5639f533 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 14:57:19 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'AddEncryptedAuthToken.js' lib to TypeScript --- src/libs/migrateOnyx.js | 2 - src/libs/migrations/AddEncryptedAuthToken.js | 42 -------------------- 2 files changed, 44 deletions(-) delete mode 100644 src/libs/migrations/AddEncryptedAuthToken.js diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 9389a9b66fbc..0bc2f1d3c04b 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -1,6 +1,5 @@ import _ from 'underscore'; import Log from './Log'; -import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken'; import RenameActiveClientsKey from './migrations/RenameActiveClientsKey'; import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; import MoveToIndexedDB from './migrations/MoveToIndexedDB'; @@ -19,7 +18,6 @@ export default function () { MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, - AddEncryptedAuthToken, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, KeyReportActionsByReportActionID, diff --git a/src/libs/migrations/AddEncryptedAuthToken.js b/src/libs/migrations/AddEncryptedAuthToken.js deleted file mode 100644 index 1c8d6a1e2a43..000000000000 --- a/src/libs/migrations/AddEncryptedAuthToken.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-disable rulesdir/no-api-in-views */ -import _ from 'underscore'; -import Onyx from 'react-native-onyx'; -import Log from '../Log'; -import ONYXKEYS from '../../ONYXKEYS'; -import * as Authentication from '../Authentication'; - -/** - * This migration adds an encryptedAuthToken to the SESSION key, if it is not present. - * - * @returns {Promise} - */ -export default function () { - return new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (session) => { - Onyx.disconnect(connectionID); - - if (session && !_.isEmpty(session.encryptedAuthToken)) { - Log.info('[Migrate Onyx] Skipped migration AddEncryptedAuthToken'); - return resolve(); - } - - if (!session || !session.authToken) { - Log.info('[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 Authentication.reauthenticate('Onyx_Migration_AddEncryptedAuthToken').then(() => { - Log.info('[Migrate Onyx] Ran migration AddEncryptedAuthToken'); - return resolve(); - }); - } - - return resolve(); - }, - }); - }); -} From 7bdb3755f438c74538823e2fdc84268859b578d2 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Wed, 20 Sep 2023 15:55:58 +0200 Subject: [PATCH 2/2] Fix prettier --- src/libs/migrateOnyx.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index a74c2a237e53..7394de694de1 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -13,14 +13,7 @@ export default function () { return new Promise((resolve) => { // Add all migrations to an array so they are executed in order - const migrationPromises = [ - MoveToIndexedDB, - RenameActiveClientsKey, - RenamePriorityModeKey, - RenameExpensifyNewsStatus, - AddLastVisibleActionCreated, - PersonalDetailsByAccountID, - ]; + const migrationPromises = [MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, PersonalDetailsByAccountID]; // Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the // previous promise to finish before moving onto the next one.