User roles

This commit is contained in:
Diego Mello 2017-11-22 13:16:49 -02:00
parent 7ade45864c
commit 15dec50d94
2 changed files with 16 additions and 0 deletions

View File

@ -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);
},

View File

@ -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());
}