From 8adab0e9270c9ccd201cbab542cf6077114bcc9b Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Tue, 2 Mar 2021 04:45:05 -0600 Subject: [PATCH] Name device used by Synapse Admin and hook up logout button (#113) * Name device used by Synapse Admin * Actually logout when the logout button is pressed so that old sessions get deleted * Fix lint --- src/synapse/authProvider.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/synapse/authProvider.js b/src/synapse/authProvider.js index 30ce600..11db5f0 100644 --- a/src/synapse/authProvider.js +++ b/src/synapse/authProvider.js @@ -10,6 +10,7 @@ const authProvider = { type: "m.login.password", user: username, password: password, + initial_device_display_name: "Synapse Admin", }), }; @@ -30,9 +31,24 @@ const authProvider = { }, // called when the user clicks on the logout button logout: () => { - console.log("logout "); - localStorage.removeItem("access_token"); - return Promise.resolve(); + console.log("logout"); + + const logout_api_url = + localStorage.getItem("base_url") + "/_matrix/client/r0/logout"; + const token = localStorage.getItem("access_token"); + + const options = { + method: "POST", + user: { + authenticated: true, + token: `Bearer ${token}`, + }, + }; + + return fetchUtils.fetchJson(logout_api_url, options).then(({ json }) => { + localStorage.removeItem("access_token"); + localStorage.removeItem("device_id"); + }); }, // called when the API returns an error checkError: ({ status }) => {