refactor(getUserTokenFromVSCode): separate the verifying process from the function
This commit is contained in:
		@@ -201,6 +201,20 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
 | 
			
		||||
        window.onload = async function() {
 | 
			
		||||
            await getUserTokenFromVSCode()
 | 
			
		||||
            .then(async userToken => {
 | 
			
		||||
                // verify user token
 | 
			
		||||
                await verifyToken(userToken)
 | 
			
		||||
                .then(result => {
 | 
			
		||||
                    // initialize user token
 | 
			
		||||
                    USERTOKEN = userToken
 | 
			
		||||
                })
 | 
			
		||||
                .catch(error => {
 | 
			
		||||
                    console.error('Error in verifying token:', error)
 | 
			
		||||
                })
 | 
			
		||||
            })
 | 
			
		||||
            .catch(error => {
 | 
			
		||||
                console.error("Failed to get user token from vscode: ", error)
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            if (USERTOKEN) {
 | 
			
		||||
                loadPageModules()
 | 
			
		||||
@@ -215,25 +229,19 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async function getUserTokenFromVSCode() {
 | 
			
		||||
            await communicateVSCodeByWebview('getUserToken', null)
 | 
			
		||||
            .then(async data => {
 | 
			
		||||
                const userToken = data.userToken
 | 
			
		||||
                if (userToken === '') {
 | 
			
		||||
                    // do nothing
 | 
			
		||||
                } else {
 | 
			
		||||
                    // verify user token
 | 
			
		||||
                    await verifyToken(userToken)
 | 
			
		||||
                        .then(result => {
 | 
			
		||||
                            USERTOKEN = userToken
 | 
			
		||||
                        })
 | 
			
		||||
                        .catch(error => {
 | 
			
		||||
                            console.error('Error in verifying token:', error)
 | 
			
		||||
                        })
 | 
			
		||||
                }
 | 
			
		||||
            return new Promise(async (resolve, reject) => {
 | 
			
		||||
                await communicateVSCodeByWebview('getUserToken', null)
 | 
			
		||||
                .then(async data => {
 | 
			
		||||
                    const userToken = data.userToken
 | 
			
		||||
 | 
			
		||||
            })
 | 
			
		||||
            .catch(error => {
 | 
			
		||||
                console.error('Failed to get user token: ', error)
 | 
			
		||||
                    if (userToken === undefined) {
 | 
			
		||||
                        reject("userToken is undefined")
 | 
			
		||||
                    }
 | 
			
		||||
                    resolve(userToken)
 | 
			
		||||
                })
 | 
			
		||||
                .catch(error => {
 | 
			
		||||
                    reject(error)
 | 
			
		||||
                })
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user