I have an angular app using AWS Amplify for user management. In my main app component, i use auth.currentAuthentificatedUser to get user data to call APIs with the right token. But my API calls are done to fast, before the auth.currentAuthentificatedUser. How can I handle this?
Main app component:
import { Component } from '@angular/core';
import {AwsService} from './aws.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public async
title = 'app';
username = '';
constructor( public awsService: AwsService) {
this.awsService.refreshsession(() => {
this.username=this.awsService.userData.username
});
}
ngOnInit() {
}
};
homepage component calling APIs
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(public dialog: MatDialog, private _data: cotationBase, public router: Router, public awsService: AwsService, public callAPI: callAPI, public snackBar: MatSnackBar) {
}
ngOnInit() {
this.callAPI.getAPI('https://api-dev.cloudyproject.pauset.fr/v0/providers',(response) => {
console.log(response);
this.awsImage = '../..'+response.aws.icon;
this.azureImage = '../..'+response.azure.icon;
},
(response) => {
console.log(response);},
)
}