refactor(user): login function store token, username only after verifying token as true
This commit is contained in:
@@ -80,7 +80,7 @@ export class DevStarExtension {
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
if (!this.user.isLogged()) {
|
||||
if (!await this.user.isLogged()) {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
const res = await this.user.login(accessToken, devstarUsername)
|
||||
if (res === 'ok') {
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import DevstarAPIHandler from './devstar-api';
|
||||
import { showErrorNotification } from './utils';
|
||||
import * as utils from './utils';
|
||||
const {
|
||||
generateKeyPairSync,
|
||||
createHash
|
||||
@@ -82,8 +82,7 @@ export default class User {
|
||||
const res = await devstarAPIHandler.verifyToken(token, username)
|
||||
if (!res) {
|
||||
throw new Error('Token verification failed')
|
||||
}
|
||||
|
||||
} else {
|
||||
// token与用户名验证通过
|
||||
// 插件登录:存储token与用户名
|
||||
this.setUserTokenToLocal(token)
|
||||
@@ -102,9 +101,11 @@ export default class User {
|
||||
|
||||
vscode.window.showInformationMessage(vscode.l10n.t('User login successfully!'))
|
||||
return 'ok'
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
await showErrorNotification('用户登录失败!')
|
||||
await utils.showErrorNotification('用户登录失败!')
|
||||
return 'login failed'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user