From 5fc98ffc49eedf4a39b81803729646bd81d189d5 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 12 Aug 2016 11:20:09 +0100 Subject: [PATCH] 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. --- src/Lifecycle.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 175a66bf96..c0fd2c13c5 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -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);