[FIX] Don't run UserDefaults credentials on Android (#1015)
* 🐛 Fix native credentials (android)
* Fix migration loop
This commit is contained in:
parent
255ea84599
commit
636518b6b3
|
@ -1,3 +1,4 @@
|
|||
import { AsyncStorage } from 'react-native';
|
||||
import { put, takeLatest, all } from 'redux-saga/effects';
|
||||
import SplashScreen from 'react-native-splash-screen';
|
||||
import RNUserDefaults from 'rn-user-defaults';
|
||||
|
@ -14,10 +15,15 @@ import database from '../lib/realm';
|
|||
import {
|
||||
SERVERS, SERVER_ICON, SERVER_NAME, SERVER_URL, TOKEN, USER_ID
|
||||
} from '../constants/userDefaults';
|
||||
import { isIOS } from '../utils/deviceInfo';
|
||||
|
||||
const restore = function* restore() {
|
||||
try {
|
||||
let hasMigration;
|
||||
if (isIOS) {
|
||||
yield RNUserDefaults.setName('group.ios.chat.rocket');
|
||||
hasMigration = yield AsyncStorage.getItem('hasMigration');
|
||||
}
|
||||
|
||||
let { token, server } = yield all({
|
||||
token: RNUserDefaults.get(RocketChat.TOKEN_KEY),
|
||||
|
@ -25,6 +31,7 @@ const restore = function* restore() {
|
|||
});
|
||||
|
||||
// get native credentials
|
||||
if (isIOS && !hasMigration) {
|
||||
const { serversDB } = database.databases;
|
||||
const servers = yield RNUserDefaults.objectForKey(SERVERS);
|
||||
if (servers) {
|
||||
|
@ -43,13 +50,15 @@ const restore = function* restore() {
|
|||
}
|
||||
});
|
||||
});
|
||||
yield AsyncStorage.setItem('hasMigration', true);
|
||||
}
|
||||
|
||||
// if not have current
|
||||
if (servers.length !== 0 && (!token || !server)) {
|
||||
if (servers && servers.length !== 0 && (!token || !server)) {
|
||||
server = servers[0][SERVER_URL];
|
||||
token = servers[0][TOKEN];
|
||||
}
|
||||
}
|
||||
|
||||
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||
yield put(setAllPreferences(sortPreferences));
|
||||
|
|
Loading…
Reference in New Issue