[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 { put, takeLatest, all } from 'redux-saga/effects';
|
||||||
import SplashScreen from 'react-native-splash-screen';
|
import SplashScreen from 'react-native-splash-screen';
|
||||||
import RNUserDefaults from 'rn-user-defaults';
|
import RNUserDefaults from 'rn-user-defaults';
|
||||||
|
@ -14,10 +15,15 @@ import database from '../lib/realm';
|
||||||
import {
|
import {
|
||||||
SERVERS, SERVER_ICON, SERVER_NAME, SERVER_URL, TOKEN, USER_ID
|
SERVERS, SERVER_ICON, SERVER_NAME, SERVER_URL, TOKEN, USER_ID
|
||||||
} from '../constants/userDefaults';
|
} from '../constants/userDefaults';
|
||||||
|
import { isIOS } from '../utils/deviceInfo';
|
||||||
|
|
||||||
const restore = function* restore() {
|
const restore = function* restore() {
|
||||||
try {
|
try {
|
||||||
|
let hasMigration;
|
||||||
|
if (isIOS) {
|
||||||
yield RNUserDefaults.setName('group.ios.chat.rocket');
|
yield RNUserDefaults.setName('group.ios.chat.rocket');
|
||||||
|
hasMigration = yield AsyncStorage.getItem('hasMigration');
|
||||||
|
}
|
||||||
|
|
||||||
let { token, server } = yield all({
|
let { token, server } = yield all({
|
||||||
token: RNUserDefaults.get(RocketChat.TOKEN_KEY),
|
token: RNUserDefaults.get(RocketChat.TOKEN_KEY),
|
||||||
|
@ -25,6 +31,7 @@ const restore = function* restore() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// get native credentials
|
// get native credentials
|
||||||
|
if (isIOS && !hasMigration) {
|
||||||
const { serversDB } = database.databases;
|
const { serversDB } = database.databases;
|
||||||
const servers = yield RNUserDefaults.objectForKey(SERVERS);
|
const servers = yield RNUserDefaults.objectForKey(SERVERS);
|
||||||
if (servers) {
|
if (servers) {
|
||||||
|
@ -43,13 +50,15 @@ const restore = function* restore() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
yield AsyncStorage.setItem('hasMigration', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not have current
|
// if not have current
|
||||||
if (servers.length !== 0 && (!token || !server)) {
|
if (servers && servers.length !== 0 && (!token || !server)) {
|
||||||
server = servers[0][SERVER_URL];
|
server = servers[0][SERVER_URL];
|
||||||
token = servers[0][TOKEN];
|
token = servers[0][TOKEN];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sortPreferences = yield RocketChat.getSortPreferences();
|
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||||
yield put(setAllPreferences(sortPreferences));
|
yield put(setAllPreferences(sortPreferences));
|
||||||
|
|
Loading…
Reference in New Issue