Get team_token from the RTS on login

Use the /login endpoint of the RTS to get the team token when the user has successfully logged in.
This commit is contained in:
Luke Barnard 2017-02-03 14:34:24 +00:00
parent 68f644c824
commit 173e80a5de
3 changed files with 28 additions and 0 deletions

View file

@ -228,6 +228,11 @@ function _restoreFromLocalStorage() {
return false;
}
}
const RtsClient = require("./RtsClient");
let rtsClient = null;
export function initRtsClient(url) {
rtsClient = new RtsClient(url);
}
/**
* Transitions to a logged-in state using the given credentials
@ -261,6 +266,17 @@ export function setLoggedIn(credentials) {
} catch (e) {
console.warn("Error using local storage: can't persist session!", e);
}
if (rtsClient) {
rtsClient.login(credentials.userId).then((teamToken) => {
localStorage.setItem("mx_team_token", teamToken);
}, (err) =>{
console.error(
"Failed to get team token on login, not persisting to localStorage",
err
);
});
}
} else {
console.warn("No local storage available: can't persist session!");
}