Merge pull request #676 from matrix-org/luke/rts-team-token-login
Get team_token from the RTS on loginpull/21833/head
commit
fe17e2452b
|
@ -23,6 +23,7 @@ import UserActivity from './UserActivity';
|
||||||
import Presence from './Presence';
|
import Presence from './Presence';
|
||||||
import dis from './dispatcher';
|
import dis from './dispatcher';
|
||||||
import DMRoomMap from './utils/DMRoomMap';
|
import DMRoomMap from './utils/DMRoomMap';
|
||||||
|
import RtsClient from './RtsClient';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called at startup, to attempt to build a logged-in Matrix session. It tries
|
* Called at startup, to attempt to build a logged-in Matrix session. It tries
|
||||||
|
@ -229,6 +230,11 @@ function _restoreFromLocalStorage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let rtsClient = null;
|
||||||
|
export function initRtsClient(url) {
|
||||||
|
rtsClient = new RtsClient(url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transitions to a logged-in state using the given credentials
|
* Transitions to a logged-in state using the given credentials
|
||||||
* @param {MatrixClientCreds} credentials The credentials to use
|
* @param {MatrixClientCreds} credentials The credentials to use
|
||||||
|
@ -261,6 +267,17 @@ export function setLoggedIn(credentials) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Error using local storage: can't persist session!", e);
|
console.warn("Error using local storage: can't persist session!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rtsClient) {
|
||||||
|
rtsClient.login(credentials.userId).then((body) => {
|
||||||
|
localStorage.setItem("mx_team_token", body.team_token);
|
||||||
|
}, (err) =>{
|
||||||
|
console.error(
|
||||||
|
"Failed to get team token on login, not persisting to localStorage",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn("No local storage available: can't persist session!");
|
console.warn("No local storage available: can't persist session!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,4 +77,21 @@ export default class RtsClient {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal to the RTS that a login has occurred and that a user requires their team's
|
||||||
|
* token.
|
||||||
|
* @param {string} userId the user ID of the user who is a member of a team.
|
||||||
|
* @returns {Promise} a promise that resolves to { team_token: 'sometoken' } upon
|
||||||
|
* success.
|
||||||
|
*/
|
||||||
|
login(userId) {
|
||||||
|
return request(this._url + '/login',
|
||||||
|
{
|
||||||
|
qs: {
|
||||||
|
user_id: userId,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,6 +215,12 @@ module.exports = React.createClass({
|
||||||
window.addEventListener('resize', this.handleResize);
|
window.addEventListener('resize', this.handleResize);
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
|
|
||||||
|
if (this.props.config.teamServerConfig &&
|
||||||
|
this.props.config.teamServerConfig.teamServerURL
|
||||||
|
) {
|
||||||
|
Lifecycle.initRtsClient(this.props.config.teamServerConfig.teamServerURL);
|
||||||
|
}
|
||||||
|
|
||||||
// the extra q() ensures that synchronous exceptions hit the same codepath as
|
// the extra q() ensures that synchronous exceptions hit the same codepath as
|
||||||
// asynchronous ones.
|
// asynchronous ones.
|
||||||
q().then(() => {
|
q().then(() => {
|
||||||
|
|
Loading…
Reference in New Issue