diff --git a/src/components/settings/Security.vue b/src/components/settings/Security.vue index 5d8aed85b3..3d900cee48 100644 --- a/src/components/settings/Security.vue +++ b/src/components/settings/Security.vue @@ -171,7 +171,7 @@ export default { } else { this.$root .getSocket() - .emit("changePassword", this.password, (res) => { + .emit("changePassword", this.$root.userID, this.password, (res) => { this.$root.toastRes(res); if (res.ok) { this.password.currentPassword = ""; diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 3272e042c3..b3afa76071 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -33,6 +33,7 @@ export default { connectCount: 0, initedSocketIO: false, }, + userID: null, username: null, remember: (localStorage.remember !== "0"), allowLoginDialog: false, // Allowed to show login dialog, but "loggedIn" have to be true too. This exists because prevent the login dialog show 0.1s in first before the socket server auth-ed. @@ -407,8 +408,11 @@ export default { if (res.ok) { this.storage().token = res.token; this.socket.token = res.token; + + const { userID, username } = this.getJWTPayload() || {}; + this.userID = userID; + this.username = username; this.loggedIn = true; - this.username = this.getJWTPayload()?.username; // Trigger Chrome Save Password history.pushState({}, ""); @@ -430,8 +434,10 @@ export default { if (! res.ok) { this.logout(); } else { + const { userID, username } = this.getJWTPayload() || {}; + this.userID = userID; + this.username = username; this.loggedIn = true; - this.username = this.getJWTPayload()?.username; } }); }, @@ -445,6 +451,7 @@ export default { this.storage().removeItem("token"); this.socket.token = null; this.loggedIn = false; + this.userID = null; this.username = null; this.clearData(); },