Avoid setting device_id to 'undefined'

Deal with the situation where synapse doesn't give us a device_id on login:
don't set the device_id to 'undefined' in localstorage.
This commit is contained in:
Richard van der Hoff 2016-08-12 11:20:09 +01:00
parent df22768f1b
commit 5fc98ffc49

View file

@ -214,11 +214,19 @@ export function setLoggedIn(credentials) {
try {
localStorage.setItem("mx_hs_url", credentials.homeserverUrl);
localStorage.setItem("mx_is_url", credentials.identityServerUrl);
localStorage.setItem("mx_user_id", credentials.userId);
localStorage.setItem("mx_device_id", credentials.deviceId);
localStorage.setItem("mx_access_token", credentials.accessToken);
localStorage.setItem("mx_is_guest", JSON.stringify(credentials.guest));
// if we didn't get a deviceId from the login, leave mx_device_id unset,
// rather than setting it to "undefined".
//
// (in this case MatrixClient doesn't bother with the crypto stuff
// - that's fine for us).
if (credentials.deviceId) {
localStorage.setItem("mx_device_id", credentials.deviceId);
}
console.log("Session persisted for %s", credentials.userId);
} catch (e) {
console.warn("Error using local storage: can't persist session!", e);