From 548ccdc57582f8ddcd2ac4691e26c9e310e943a7 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Sun, 22 Jun 2025 16:15:14 +0800 Subject: [PATCH] refactor(user): isLogged add validity verification for username and token --- src/user.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/user.ts b/src/user.ts index 1371999..b7cda49 100644 --- a/src/user.ts +++ b/src/user.ts @@ -116,18 +116,19 @@ export default class User { vscode.window.showInformationMessage(vscode.l10n.t("User has logged out!")) } - public isLogged() { - var existUsername = false; - var existUserToken = false; - if (this.username != undefined && this.username != '') { - existUsername = true; - } - if (this.userToken != undefined && this.userToken != '') { - existUserToken = true; - } + public async isLogged(): Promise { + const username: string|undefined = this.context.globalState.get(this.usernameKey) + const userToken: string|undefined = this.context.globalState.get(this.userTokenKey) + if ((username != undefined && username != '') && (userToken != undefined && userToken != '')) { + const devstarAPIHandler = new DevstarAPIHandler(this.devstarDomain) - if (existUsername && existUserToken) { - return true; + const res = await devstarAPIHandler.verifyToken(userToken, username) + if (!res) { + console.error("username or token is error") + return false; + } else { + return true; + } } else { return false; }