Good morning, I created an angualr app and I need to check users role in routing. I created a service "RoleGuardService" with a method canLoad that read the JWS token and check the user permission:
import * as JWT from 'jwt-decode';
...
const tokenPayload: App = JWT(token);
if(tokenPayload.UserType == expectedRole){
return true;
}
return false;
So far so good, but this force me to declare the permission hard coded:
{ path: 'xxx', component: yyy, canLoad: [RoleGuardService], data: { expectedRole: 'Admin' } },
Is possible to create a method that requires authorization directly from the web API? like:
var isAllowed = false;
this.http.get('https://xxx/check_user/').subscribe(result: bool) => {
isAllowed = result;
}
///wait until the subscribe is called
return isAllowed;