refactor(user): isLogged add validity verification for username and token
This commit is contained in:
23
src/user.ts
23
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<boolean> {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user