[FIX] Select user from native credentials (#1266)
This commit is contained in:
parent
67fb14fa9d
commit
6fd722a0d8
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
user = userCredentials && {
|
||||
token: userCredentials[TOKEN]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const servers = yield RNUserDefaults.objectForKey(SERVERS);
|
||||
const userCredentials = servers && servers.find(srv => srv[SERVER_URL] === server);
|
||||
const userLogin = 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 });
|
||||
|
|
Loading…
Reference in New Issue