I have an Angular application in which I am trying to manage the login using MSAL. Apparently I'm having a problem and from what I've found online, I'm not providing a provider for PublicClientApplication in my Angular application. This is the error I get:
ERROR NullInjectorError: R3InjectorError(AppModule)[PublicClientApplication -> PublicClientApplication -> PublicClientApplication]:
NullInjectorError: No provider for PublicClientApplication!
at NullInjector.get (core.mjs:7493:27)
at R3Injector.get (core.mjs:7914:33)
at R3Injector.get (core.mjs:7914:33)
at R3Injector.get (core.mjs:7914:33)
at ChainedInjector.get (core.mjs:12084:36)
at lookupTokenUsingModuleInjector (core.mjs:3201:39)
at getOrCreateInjectable (core.mjs:3246:12)
at Module.ɵɵdirectiveInject (core.mjs:10041:12)
at NodeInjectorFactory.AppComponent_Factory [as factory] (app.component.ts:12:26)
at getNodeInjectable (core.mjs:3431:44)
This is the function I have in my app.module
export function MSALInstanceFactory() : IPublicClientApplication {
return new PublicClientApplication({
auth: {
clientId: "((my client id))",
authority:
"my authority",
redirectUri: "my redirect uri",
},
system: {
allowNativeBroker: false,
}
})
}
And these are the providers I'm using:
provide : MSAL_INSTANCE,
useFactory : MSALInstanceFactory,
},
MsalService,
MsalGuard,
MsalBroadcastService,
I tried to instantiate this function in my app.component
ngOnInit() {
try {
MSALInstanceFactory
} catch (error) {
}
}