diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 170a07a7..affac4f8 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -1,5 +1,6 @@ import { io } from "socket.io-client"; import { useToast } from "vue-toastification"; +import jwt_decode from "jwt-decode"; const toast = useToast(); let socket; @@ -217,6 +218,15 @@ export default { return (this.remember) ? localStorage : sessionStorage; }, + getJWTPayload() { + const jwtToken = this.$root.storage().token; + + if (jwtToken && jwtToken !== "autoLogin") { + return jwt_decode(jwtToken); + } + return undefined; + }, + getSocket() { return socket; }, diff --git a/src/pages/Settings.vue b/src/pages/Settings.vue index 9312b0c2..9d501407 100644 --- a/src/pages/Settings.vue +++ b/src/pages/Settings.vue @@ -306,7 +306,7 @@
这是为 有第三方认证 的用户提供的功能,如 Cloudflare Access
请谨慎使用!
- +你是否要取消登入驗證?
此功能是設計給已有第三方認證的使用者,例如 Cloudflare Access。
@@ -515,9 +515,11 @@ export default { }, loadUsername() { - const jwtToken = this.$root.storage().token; - const jwtPayload = jwt_decode(jwtToken); - this.username = jwtPayload.username; + const jwtPayload = this.$root.getJWTPayload(); + + if (jwtPayload) { + this.username = jwtPayload.username; + } }, loadSettings() { @@ -568,6 +570,7 @@ export default { this.settings.disableAuth = false; this.saveSettings(); this.$root.storage().removeItem("token"); + location.reload(); }, downloadBackup() {