Answer the question
In order to leave comments, you need to log in
How to wait for application initialization?
There is CanActive, which stands on a certain route in order to prevent transitions along forbidden routes depending on roles.
So, this CanActive fires before the event of accessing the user data request API...
I tried to initialize the user through APP_INITIALIZER:
export function appInitializerFactory(authService: AuthorizationService, permissionsService: PermissionService) {
console.log("appInitializerFactory1");
return async () => {
authService.authorize().pipe(tap(() => {
permissionsService.currentUser = authService.currentUser;
console.log("appInitializerFactory2");
})).toPromise();
};
}
Answer the question
In order to leave comments, you need to log in
return forgot
and async is not needed there
and format normally
export function appInitializerFactory(
authService: AuthorizationService,
permissionsService: PermissionService,
) {
return () => authService.authorize().pipe(
tap(() => permissionsService.currentUser = authService.currentUser),
)
.toPromise();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question