From c6b6e54617265490f9516e095abe40086f5b33df Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 16 Mar 2021 12:13:32 +0100 Subject: [PATCH] Fix broken redirect to login page (#116) --- src/synapse/authProvider.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/synapse/authProvider.js b/src/synapse/authProvider.js index 11db5f0..972d599 100644 --- a/src/synapse/authProvider.js +++ b/src/synapse/authProvider.js @@ -35,20 +35,23 @@ const authProvider = { const logout_api_url = localStorage.getItem("base_url") + "/_matrix/client/r0/logout"; - const token = localStorage.getItem("access_token"); + const access_token = localStorage.getItem("access_token"); const options = { method: "POST", user: { authenticated: true, - token: `Bearer ${token}`, + token: `Bearer ${access_token}`, }, }; - return fetchUtils.fetchJson(logout_api_url, options).then(({ json }) => { - localStorage.removeItem("access_token"); - localStorage.removeItem("device_id"); - }); + if (typeof access_token === "string") { + fetchUtils.fetchJson(logout_api_url, options).then(({ json }) => { + localStorage.removeItem("access_token"); + localStorage.removeItem("device_id"); + }); + } + return Promise.resolve(); }, // called when the API returns an error checkError: ({ status }) => { @@ -62,7 +65,7 @@ const authProvider = { checkAuth: () => { const access_token = localStorage.getItem("access_token"); console.log("checkAuth " + access_token); - return typeof access_token == "string" + return typeof access_token === "string" ? Promise.resolve() : Promise.reject(); },