As far as I understand I shouldn't really use async/await methods in Angular.
So I'm trying to figure out how to get it going without those methods.
I'm using canActivate function which first of all calls AuthService which asks PHP if current JWT token is valid. However, at the current moment I accomplished this only by doing so:
canActivate
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
{
var valid_token: boolean;
var role: number;
await this.auth.validate_token()
.then(res =>
{
valid_token = res['valid_token'],
role = res['role']
});
//define if current user can access
}
validate_token
validate_token()
{
return this.http.post(globals.api_url("verify-token.php"),
{
jwt: localStorage.getItem('token')
}).toPromise()
.then(result => result)
.catch(result => result['valid_token'] = false);
}
And by now I have to call this validate_token()
function in some other places and I don't want to set every function for async/await.
I was playing around some with observables but still wihout any proper result.
verify-token.php returns if current token is valid and some other user proporties