refactor: set null string '' as the null value of user token
This commit is contained in:
		@@ -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')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user