refactor: set null string '' as the null value of user token

This commit is contained in:
Levi Yan
2024-10-23 12:54:50 +08:00
parent 4ded936bf7
commit 0a31591150
2 changed files with 9 additions and 8 deletions

View File

@@ -49,7 +49,7 @@ export default class DSHome {
case 'getUserToken':
const userToken = this.context.globalState.get('devstarUserToken')
if (userToken === undefined) {
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: 'none'}})
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: ''}})
break;
} else {
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}})

View File

@@ -200,7 +200,8 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
var PROJECTLIST = []
window.onload = async function() {
await getUserTokenFromVscode()
await getUserTokenFromVSCode()
if (USERTOKEN) {
loadPageModules()
} else {
@@ -213,11 +214,11 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
// loadProjects()
}
async function getUserTokenFromVscode() {
async function getUserTokenFromVSCode() {
await communicateVSCodeByWebview('getUserToken', null)
.then(async data => {
const userToken = data.userToken
if (userToken === 'none') {
if (userToken === '') {
// do nothing
} else {
// verify user token
@@ -231,9 +232,9 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
}
})
.catch(error => [
console.log('Failed to get user token: ', error)
])
.catch(error => {
console.error('Failed to get user token: ', error)
})
}
function verifyToken(token) {
@@ -345,7 +346,7 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
function logout() {
// remove token from global variable and vscode global state
USERTOKEN = null
communicateVSCodeByWebview('setUserToken', { userToken: 'none'})
communicateVSCodeByWebview('setUserToken', { userToken: ''})
.then(result => {
if (result.ok) {
console.log('User token has been removed from vscode global state')