Switch to async/await schema for all asynchronous function calls.
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user