[FIX] Select user from native credentials (#1266)

This commit is contained in:
Djorkaeff Alexandre 2019-10-02 09:55:25 -03:00 committed by Diego Mello
parent 67fb14fa9d
commit 6fd722a0d8
2 changed files with 21 additions and 23 deletions

View File

@ -231,11 +231,11 @@ const RocketChat = {
const userCollections = serversDB.collections.get('users');
let user = null;
if (userId) {
user = await userCollections.find(userId);
const userRecord = await userCollections.find(userId);
user = {
id: user.id,
token: user.token,
username: user.username
id: userRecord.id,
token: userRecord.token,
username: userRecord.username
};
}
reduxStore.dispatch(shareSetUser({

View File

@ -61,31 +61,29 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
let user = null;
if (userId) {
try {
user = yield userCollections.find(userId);
const userRecord = yield userCollections.find(userId);
user = {
id: user.id,
token: user.token,
username: user.username,
name: user.name,
language: user.language,
status: user.status,
roles: user.roles
id: userRecord.id,
token: userRecord.token,
username: userRecord.username,
name: userRecord.name,
language: userRecord.language,
status: userRecord.status,
roles: userRecord.roles
};
user = { ...user, roles: JSON.parse(user.roles) };
} catch (e) {
// do nothing?
}
}
// We only run it if not has user on DB
const servers = yield RNUserDefaults.objectForKey(SERVERS);
const userCredentials = servers && servers.find(srv => srv[SERVER_URL] === server);
const userLogin = userCredentials && {
user = userCredentials && {
token: userCredentials[TOKEN]
};
}
}
if (user || userLogin) {
yield RocketChat.connect({ server, user: user || userLogin });
yield put(setUser(user || userLogin));
if (user) {
yield RocketChat.connect({ server, user });
yield put(setUser(user));
yield put(actions.appStart('inside'));
} else {
yield RocketChat.connect({ server });