Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: profile issue async/await #123

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class Context extends EventEmitter {

// If there is no profile loaded skip, do not load a context.
if (!profile) {
this.loaded = true;
return;
}

Expand Down Expand Up @@ -242,20 +243,20 @@ export class Context extends EventEmitter {
return this.config.getProfileName();
}

addAndSaveProfile(name: string, appPassword: AppPassword, region: string) {
this.config.addAndSaveProfile(name, appPassword, region);
this.loadContext();
async addAndSaveProfile(name: string, appPassword: AppPassword, region: string) {
await this.config.addAndSaveProfile(name, appPassword, region);
await this.loadContext();
}

removeAndSaveProfile(name: string) {
async removeAndSaveProfile(name: string) {
this.config.removeAndSaveProfile(name);
this.loadContext();
await this.loadContext();
}

setProfile(name: string) {
async setProfile(name: string) {
this.config.setProfile(name);
this.environment = undefined;
this.loadContext();
await this.loadContext();
}

handleErr(err: Error) {
Expand Down
15 changes: 10 additions & 5 deletions src/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
* @param name name of the profile.
* @param webviewView webview of the provider.
*/
checkLoginServerResponse(
async checkLoginServerResponse(
appPasswordResponse: AppPasswordResponse | undefined,
name: string,
webviewView: vscode.WebviewView
Expand All @@ -184,7 +184,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
// Set the state loading to true. After the new context is loaded
// loading will turn false.
this.state.isLoading = true;
this.context.addAndSaveProfile(name, appPassword, region.toString());
await this.context.addAndSaveProfile(name, appPassword, region.toString());
} else {
// Cancel login process.
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
Expand All @@ -211,10 +211,14 @@ export default class AuthProvider implements vscode.WebviewViewProvider {

webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
loginServer(name).then((appPasswordResponse) => {
this.checkLoginServerResponse(appPasswordResponse, name, webviewView);
this.checkLoginServerResponse(appPasswordResponse, name, webviewView).then(() => {
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
});
}).catch((err) => {
console.error("Error setting up the server: ", err);
vscode.window.showErrorMessage('Internal error while waiting for the credentials.');
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);

});
break;
}
Expand Down Expand Up @@ -261,7 +265,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
const name = this.context.getProfileName();

if (name) {
this.context.removeAndSaveProfile(name);
await this.context.removeAndSaveProfile(name);
} else {
console.error("[Auth]", "Profile name is not available.");
}
Expand Down Expand Up @@ -332,9 +336,10 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();

console.log("Is loading: ", this.state.isLoading);
let content = (
`
<vscode-text-field id="profileNameInput">Profile Name</vscode-text-field>
<vscode-text-field id="profileNameInput" ${this.state.isLoading ? "disabled": ""}>Profile Name</vscode-text-field>
<p id="invalidProfileNameErrorMessage">Profile name must contain only ASCII letters, ASCII digits, underscores, and dashes.</p>
<div class="setup-container-actions">
<vscode-button appearence="primary" id="continueProfileButton" class="action_button" disabled=true>Continue</vscode-button>
Expand Down