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