From 9ddd2c73653a2c22e03c8dadc93b69d9c25e12f4 Mon Sep 17 00:00:00 2001 From: Andreas Brett Date: Mon, 25 Oct 2021 01:23:02 +0200 Subject: [PATCH] use jwt --- server/server.js | 20 -------------------- src/pages/Settings.vue | 8 +++++--- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/server/server.js b/server/server.js index a21694634..11f03061a 100644 --- a/server/server.js +++ b/server/server.js @@ -894,26 +894,6 @@ exports.entryPage = "dashboard"; } }); - socket.on("getUsername", async (callback) => { - try { - checkLogin(socket); - - let user = await R.findOne("user", " id = ? AND active = 1 ", [ - socket.userID, - ]); - - callback({ - ok: true, - data: user.username, - }); - } catch (e) { - callback({ - ok: false, - msg: e.message, - }); - } - }); - socket.on("getSettings", async (callback) => { try { checkLogin(socket); diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 292098107..2ac856433 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -487,9 +487,11 @@ export default { }, loadUsername() { - this.$root.getSocket().emit("getUsername", (res) => { - this.username = res.data; - }); + const jwtToken = localStorage.getItem("token"); + const [match, headerBase64, payloadBase64, signatureBase64] = jwtToken.match(/^(\S+)\.(\S+)\.(\S+)$/i); + const payload = atob(payloadBase64); + const oPayload = JSON.parse(payload); + this.username = oPayload.username; }, loadSettings() {