[FIX] Run credentials migration only once (#1245)
This commit is contained in:
parent
3dd47519fe
commit
22cadb1041
|
@ -33,6 +33,7 @@ const restore = function* restore() {
|
|||
server: RNUserDefaults.get('currentServer')
|
||||
});
|
||||
|
||||
if (!hasMigration && isIOS) {
|
||||
let servers = yield RNUserDefaults.objectForKey(SERVERS);
|
||||
// if not have current
|
||||
if (servers && servers.length !== 0 && (!token || !server)) {
|
||||
|
@ -41,13 +42,13 @@ const restore = function* restore() {
|
|||
}
|
||||
|
||||
// get native credentials
|
||||
if (servers && !hasMigration) {
|
||||
if (servers) {
|
||||
try {
|
||||
// parse servers
|
||||
servers = yield Promise.all(servers.map(async(s) => {
|
||||
await RNUserDefaults.set(`${ RocketChat.TOKEN_KEY }-${ s[SERVER_URL] }`, s[USER_ID]);
|
||||
return ({ id: s[SERVER_URL], name: s[SERVER_NAME], iconURL: s[SERVER_ICON] });
|
||||
}));
|
||||
try {
|
||||
const serversDB = database.servers;
|
||||
yield serversDB.action(async() => {
|
||||
const serversCollection = serversDB.collections.get('servers');
|
||||
|
@ -76,6 +77,13 @@ const restore = function* restore() {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
yield AsyncStorage.setItem('hasMigration', '1');
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||
yield put(setAllPreferences(sortPreferences));
|
||||
|
||||
|
@ -91,7 +99,7 @@ const restore = function* restore() {
|
|||
RNUserDefaults.clear('currentServer')
|
||||
]);
|
||||
yield put(actions.appStart('outside'));
|
||||
} else if (server) {
|
||||
} else {
|
||||
const serversDB = database.servers;
|
||||
const serverCollections = serversDB.collections.get('servers');
|
||||
const serverObj = yield serverCollections.find(server);
|
||||
|
|
Loading…
Reference in New Issue