diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 6cb4235c58c8..048eeca5f76f 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -662,6 +662,8 @@ PODS: - Firebase/Performance (= 8.8.0) - React-Core - RNFBApp + - RNFS (2.20.0): + - React-Core - RNGestureHandler (2.9.0): - React-Core - RNLocalize (2.2.6): @@ -809,6 +811,7 @@ DEPENDENCIES: - "RNFBApp (from `../node_modules/@react-native-firebase/app`)" - "RNFBCrashlytics (from `../node_modules/@react-native-firebase/crashlytics`)" - "RNFBPerf (from `../node_modules/@react-native-firebase/perf`)" + - RNFS (from `../node_modules/react-native-fs`) - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) - RNLocalize (from `../node_modules/react-native-localize`) - RNPermissions (from `../node_modules/react-native-permissions`) @@ -999,6 +1002,8 @@ EXTERNAL SOURCES: :path: "../node_modules/@react-native-firebase/crashlytics" RNFBPerf: :path: "../node_modules/@react-native-firebase/perf" + RNFS: + :path: "../node_modules/react-native-fs" RNGestureHandler: :path: "../node_modules/react-native-gesture-handler" RNLocalize: @@ -1120,6 +1125,7 @@ SPEC CHECKSUMS: RNFBApp: 729c0666395b1953198dc4a1ec6deb8fbe1c302e RNFBCrashlytics: 2061ca863e8e2fa1aae9b12477d7dfa8e88ca0f9 RNFBPerf: 389914cda4000fe0d996a752532a591132cbf3f9 + RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 RNGestureHandler: 071d7a9ad81e8b83fe7663b303d132406a7d8f39 RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81 RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c diff --git a/jest/setup.js b/jest/setup.js index 228f3a22f33b..f03c53540359 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -25,3 +25,9 @@ jest.spyOn(console, 'debug').mockImplementation((...params) => { // eslint-disable-next-line no-console console.log('DEBUG', ...params); }); + +// This mock is required for mocking file systems when running tests +jest.mock('react-native-fs', () => ({ + unlink: jest.fn(() => new Promise((res) => res())), + CachesDirectoryPath: jest.fn(), +})); diff --git a/package-lock.json b/package-lock.json index 369dd6f6e1b0..b2600d80658d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,6 +68,7 @@ "react-native-device-info": "^10.3.0", "react-native-document-picker": "^8.0.0", "react-native-fast-image": "^8.6.3", + "react-native-fs": "^2.20.0", "react-native-gesture-handler": "2.9.0", "react-native-google-places-autocomplete": "git+https://github.com/Expensify/react-native-google-places-autocomplete.git#6f436a06a3018cb49750bb110b89df75f6a865d5", "react-native-haptic-feedback": "^1.13.0", @@ -36206,6 +36207,24 @@ "react-native": ">0.62.0" } }, + "node_modules/react-native-fs": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.20.0.tgz", + "integrity": "sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ==", + "dependencies": { + "base-64": "^0.1.0", + "utf8": "^3.0.0" + }, + "peerDependencies": { + "react-native": "*", + "react-native-windows": "*" + }, + "peerDependenciesMeta": { + "react-native-windows": { + "optional": true + } + } + }, "node_modules/react-native-gesture-handler": { "version": "2.9.0", "license": "MIT", @@ -41385,6 +41404,11 @@ "react": "^16.8.0 || ^17.0.0 || ^18.0.0" } }, + "node_modules/utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", + "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==" + }, "node_modules/utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", @@ -67500,6 +67524,15 @@ "dev": true, "requires": {} }, + "react-native-fs": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.20.0.tgz", + "integrity": "sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ==", + "requires": { + "base-64": "^0.1.0", + "utf8": "^3.0.0" + } + }, "react-native-gesture-handler": { "version": "2.9.0", "requires": { @@ -70847,6 +70880,11 @@ "version": "1.2.0", "requires": {} }, + "utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", + "integrity": "sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==" + }, "utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", diff --git a/package.json b/package.json index 6c9d9b946898..e5dd68043958 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "react-native-device-info": "^10.3.0", "react-native-document-picker": "^8.0.0", "react-native-fast-image": "^8.6.3", + "react-native-fs": "^2.20.0", "react-native-gesture-handler": "2.9.0", "react-native-google-places-autocomplete": "git+https://github.com/Expensify/react-native-google-places-autocomplete.git#6f436a06a3018cb49750bb110b89df75f6a865d5", "react-native-haptic-feedback": "^1.13.0", diff --git a/src/libs/actions/Session/clearCache/index.js b/src/libs/actions/Session/clearCache/index.js new file mode 100644 index 000000000000..9ccd0193cfbd --- /dev/null +++ b/src/libs/actions/Session/clearCache/index.js @@ -0,0 +1,5 @@ +function clearStorage() { + return new Promise((res) => res()); +} + +export default clearStorage; diff --git a/src/libs/actions/Session/clearCache/index.native.js b/src/libs/actions/Session/clearCache/index.native.js new file mode 100644 index 000000000000..3bd647dbf8fb --- /dev/null +++ b/src/libs/actions/Session/clearCache/index.native.js @@ -0,0 +1,8 @@ +import {CachesDirectoryPath, unlink} from 'react-native-fs'; + +function clearStorage() { + // `unlink` is used to delete the caches directory + return unlink(CachesDirectoryPath); +} + +export default clearStorage; diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index b53d7811ef8d..f59cf5972c9e 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import {Linking} from 'react-native'; +import clearCache from './clearCache'; import ONYXKEYS from '../../../ONYXKEYS'; import redirectToSignIn from '../SignInRedirect'; import CONFIG from '../../../CONFIG'; @@ -72,7 +73,9 @@ function signOut() { partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, shouldRetry: false, }); - + clearCache().then(() => { + Log.info('Cleared all chache data', true, {}, true); + }); Timing.clearData(); }