diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 1eb80bb2f..282ed1e71 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -149,6 +149,17 @@ const RocketChat = { }).then(response => response.json()); }, + userInfo({ server, token, userId }) { + return fetch(`${ server }/api/v1/users.info?userId=${ userId }`, { + method: 'get', + headers: { + 'Content-Type': 'application/json', + 'X-Auth-Token': token, + 'X-User-Id': userId + } + }).then(response => response.json()); + }, + register({ credentials }) { return call('registerUser', credentials); }, diff --git a/app/sagas/login.js b/app/sagas/login.js index 0838aea02..eb767e87f 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -26,6 +26,7 @@ const setUsernameCall = args => RocketChat.setUsername(args); const logoutCall = args => RocketChat.logout(args); const meCall = args => RocketChat.me(args); const forgotPasswordCall = args => RocketChat.forgotPassword(args); +const userInfoCall = args => RocketChat.userInfo(args); const getToken = function* getToken() { const currentServer = yield select(getServer); @@ -76,6 +77,10 @@ const handleLoginRequest = function* handleLoginRequest({ credentials }) { // if user has username if (me.username) { user.username = me.username; + const userInfo = yield call(userInfoCall, { server, token: user.token, userId: user.id }); + if (userInfo.user.roles) { + user.roles = userInfo.user.roles; + } } else { yield put(registerIncomplete()); }