Switch to async/await schema for all asynchronous function calls.

This commit is contained in:
Spencer Ofwiti
2021-03-18 12:10:55 +03:00
parent 6dc44be4eb
commit 9ec50e9c1a
10 changed files with 61 additions and 68 deletions

View File

@@ -22,35 +22,33 @@ export class AuthComponent implements OnInit {
private router: Router
) { }
ngOnInit(): void {
async ngOnInit(): Promise<void> {
this.keyForm = this.formBuilder.group({
key: ['', Validators.required],
});
if (this.authService.privateKey !== undefined ) {
this.authService.setKey(this.authService.privateKey).then(r => {
if (this.authService.sessionToken !== undefined) {
this.authService.setState(
'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken);
}
});
if (this.authService.privateKey !== undefined) {
const setKey = await this.authService.setKey(this.authService.privateKey);
if (setKey && this.authService.sessionToken !== undefined) {
this.authService.setState(
'Click button to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken);
}
}
}
get keyFormStub(): any { return this.keyForm.controls; }
onSubmit(): void {
async onSubmit(): Promise<void> {
this.submitted = true;
if (this.keyForm.invalid) { return; }
this.loading = true;
this.authService.setKey(this.keyFormStub.key.value).then();
await this.authService.setKey(this.keyFormStub.key.value);
this.loading = false;
}
login(): void {
const loginStatus = this.authService.login();
console.log(loginStatus);
if (loginStatus) {
this.router.navigate(['/home']);
}