[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')
|
server: RNUserDefaults.get('currentServer')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!hasMigration && isIOS) {
|
||||||
let servers = yield RNUserDefaults.objectForKey(SERVERS);
|
let servers = yield RNUserDefaults.objectForKey(SERVERS);
|
||||||
// if not have current
|
// if not have current
|
||||||
if (servers && servers.length !== 0 && (!token || !server)) {
|
if (servers && servers.length !== 0 && (!token || !server)) {
|
||||||
|
@ -41,13 +42,13 @@ const restore = function* restore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get native credentials
|
// get native credentials
|
||||||
if (servers && !hasMigration) {
|
if (servers) {
|
||||||
|
try {
|
||||||
// parse servers
|
// parse servers
|
||||||
servers = yield Promise.all(servers.map(async(s) => {
|
servers = yield Promise.all(servers.map(async(s) => {
|
||||||
await RNUserDefaults.set(`${ RocketChat.TOKEN_KEY }-${ s[SERVER_URL] }`, s[USER_ID]);
|
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] });
|
return ({ id: s[SERVER_URL], name: s[SERVER_NAME], iconURL: s[SERVER_ICON] });
|
||||||
}));
|
}));
|
||||||
try {
|
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
yield serversDB.action(async() => {
|
yield serversDB.action(async() => {
|
||||||
const serversCollection = serversDB.collections.get('servers');
|
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();
|
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||||
yield put(setAllPreferences(sortPreferences));
|
yield put(setAllPreferences(sortPreferences));
|
||||||
|
|
||||||
|
@ -91,7 +99,7 @@ const restore = function* restore() {
|
||||||
RNUserDefaults.clear('currentServer')
|
RNUserDefaults.clear('currentServer')
|
||||||
]);
|
]);
|
||||||
yield put(actions.appStart('outside'));
|
yield put(actions.appStart('outside'));
|
||||||
} else if (server) {
|
} else {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serverCollections = serversDB.collections.get('servers');
|
const serverCollections = serversDB.collections.get('servers');
|
||||||
const serverObj = yield serverCollections.find(server);
|
const serverObj = yield serverCollections.find(server);
|
||||||
|
|
Loading…
Reference in New Issue