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