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': case 'getUserToken':
const userToken = this.context.globalState.get('devstarUserToken') const userToken = this.context.globalState.get('devstarUserToken')
if (userToken === undefined) { if (userToken === undefined) {
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: 'none'}}) panel.webview.postMessage({ command: 'getUserToken', data: {userToken: ''}})
break; break;
} else { } else {
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}}) panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}})

View File

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