I work on an Angular (currently v7) application which is using the APP_INITIALIZER to check if the user is logged in. The code is pretty straight-forward, I add the APP_INITIALIZER
@NgModule({
...,
providers: [
...,
{
provide: APP_INITIALIZER,
useFactory: CheckLoginFactory,
deps: [Initialization, AuthService, ObservableState],
multi: true
}
]
using this factory:
export function CheckLoginFactory(
init: any,
auth: AuthService,
oss: ObservableState
) {
const confirmLogin = auth
.confirmLogin()
.pipe(catchError(val => of(undefined)));
return () => confirmLogin.toPromise();
}
and the confirmLogin-function checks whether the user is logged in
confirmLogin(): Observable<User> {
return this.get('authentication/login').pipe(
map(response => plainToClass(User, response as Object))
);
}
So far so simple, this code has been working for the last year. Now I restructured the app and implemented lazy loading for all subpages of the app and now this code does not work anymore. The http-request send from confirmLogin always shows up as canceled in the dev-tools and the factory runs into the .pipe(catchError(val => of(undefined)));.
Is there anything that is different on how Angular handles the APP_INITIALIZER in apps using / not using lazy loading?