I have a monorepo that contains several applications as well as some shared libraries. What I am trying to do is implement an authGuard
for some of the pages in the applications, however the issue I am running into is that, in the context of the router, my AuthService
has no provider.
This is because the dependencies of AuthService
look like this:
AuthService -> FirebaseAuthService -> FirebaseAppService -> EnvironmentService
On top of that, I am trying to prevent services and modules being initialized unnecessarily. So, AuthService
should only be initialized if I try to navigate to a page that requires authentication, or I am on the authentication page (ideally, I would have some informational pages that don’t require auth).
Attempting to wrap my guard in runInInjectionContext
seems to make things worse because not only can I not use an NgModule
type as a value for the Injector
parameter, but writing the function for the second parameter in a way that satisfies the CanMatchFn
specs makes it so that there are even more errors.
I really can’t provide AuthService
in ‘root’ because of the initialization process for the app’s environment.