Skip to content

Commit

Permalink
Clear cookies but keep files (#5479)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored Jun 24, 2021
1 parent afe80b6 commit f7071c2
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions app/init/global_event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AsyncStorage from '@react-native-community/async-storage';
import CookieManager from '@react-native-cookies/cookies';
import DeviceInfo from 'react-native-device-info';
import {getLocales} from 'react-native-localize';
import RNFetchBlob from 'rn-fetch-blob';

import {setDeviceDimensions, setDeviceOrientation, setDeviceAsTablet} from '@actions/device';
import {selectDefaultChannel} from '@actions/views/channel';
Expand Down Expand Up @@ -140,44 +139,14 @@ class GlobalEventHandler {

clearCookiesAndWebData = async () => {
try {
await CookieManager.clearAll(Platform.OS === 'ios');
} catch (error) {
// Nothing to clear
}

switch (Platform.OS) {
case 'ios': {
const mainPath = RNFetchBlob.fs.dirs.DocumentDir.split('/').slice(0, -1).join('/');
const libraryDir = `${mainPath}/Library`;
const cookiesDir = `${libraryDir}/Cookies`;
const cookies = await RNFetchBlob.fs.exists(cookiesDir);
const webkitDir = `${libraryDir}/WebKit`;
const webkit = await RNFetchBlob.fs.exists(webkitDir);

if (cookies) {
RNFetchBlob.fs.unlink(cookiesDir);
}
await CookieManager.clearAll(true);

if (webkit) {
RNFetchBlob.fs.unlink(webkitDir);
if (Platform.OS === 'ios') {
// on iOS we will also detele the Cookies stored by NSCookieStore
await CookieManager.clearAll(false);
}
break;
}

case 'android': {
const cacheDir = RNFetchBlob.fs.dirs.CacheDir;
const mainPath = cacheDir.split('/').slice(0, -1).join('/');
const cookies = await RNFetchBlob.fs.exists(`${mainPath}/app_webview/Cookies`);
const cookiesJ = await RNFetchBlob.fs.exists(`${mainPath}/app_webview/Cookies-journal`);
if (cookies) {
RNFetchBlob.fs.unlink(`${mainPath}/app_webview/Cookies`);
}

if (cookiesJ) {
RNFetchBlob.fs.unlink(`${mainPath}/app_webview/Cookies-journal`);
}
break;
}
} catch (error) {
// Nothing to do
}
};

Expand Down

0 comments on commit f7071c2

Please sign in to comment.