Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Angular 8 + @auth0/angular-jwt #138

Open
Inexad opened this issue Oct 2, 2019 · 12 comments
Open

Angular 8 + @auth0/angular-jwt #138

Inexad opened this issue Oct 2, 2019 · 12 comments
Labels

Comments

@Inexad
Copy link

Inexad commented Oct 2, 2019

All my http bearer tokens (JWT) get removed after including: NgChatModule in my app.module.ts.

I'm using package @auth0/angular-jwt for handling my bearer tokens. It uses a http interceptor and add the token to http header. For some reason this bearer is lost if i import NgChatModule. If i remove NgChatModule it works as intended.

Is NgChatModule interfering with some http interception ?

@rpaschoal
Copy link
Owner

Hi @Inexad ,

ng-chat does use the HttpClientModule as part of its imports. It's mainly used to handle file uploads. Do you have the setting to enable file uploads on?

In terms of headers or possible interference I can't think of anything that could be causing such behavior. Have a look at this file as this is where ng-chat uses a HttpClient instance: https://github.com/rpaschoal/ng-chat/blob/master/src/ng-chat/core/default-file-upload-adapter.ts

Perhaps it could be related to your adapter implementation?

@Inexad
Copy link
Author

Inexad commented Oct 3, 2019

Hi @rpaschoal,

The ng-chat code i use is the example i found here:

https://github.com/rpaschoal/ng-chat-netcoreapp/tree/master/NgChatClient/ClientApp/src/app

The wierd thing is that if i remove all code related to the example and only import the module (No adapters, no components eg) i get the same behaviour.

I will try to reproduce this in a clean angular project.

Regards.

@Inexad
Copy link
Author

Inexad commented Oct 3, 2019

Hi again,

I could reproduce the problem and it appears to be because of lazy-loading. Everything works as normal when not including "ngchatmodule" in the lazy loaded module. After loading it into lazy-loaded module the bearer token for some reason gets removed from authentication header.

When importing chat-component and ngchatmodule directly into app.module it works. But not into lazy loaded module.

Is there any way to get this working with Lazy Loaded modules?

I've tried to upload the files to a StackBlitz (not sure why its not working): https://stackblitz.com/edit/angular-vmj9zf

Regards.

@rpaschoal
Copy link
Owner

@Inexad this seems related: angular/angular#20575

Some interesting read on this on another lib: dimpu/ngx-md#159 and here a PR to address the issue on the same lib dimpu/ngx-md#169

Long story short this seems to be by design on Angular and I am not too sure if we should remove the HttpClientModule registration from ng-chat as ng-chat does need it. All off the sudden if we remove it, it could break the usage for other people who might not have imported the HttpClientModule module on their main Angular application.

On your application is it a blocker to have the ng-chat module loaded up with the main application module?

@Inexad
Copy link
Author

Inexad commented Oct 6, 2019

@rpaschoal I think removing the HttpClientModule would not be a good idea. If i understand this correct, the Angular handling these issues with the "forRoot()" and "forChild()" methods? Is it possible to implement forRoot() in ngchat?

Sadly it is a problem. The application is quite big and i'm trying to keep the different bundles down by lazy loading.

@rpaschoal
Copy link
Owner

I see @Inexad , would you be keen on creating a fork of ng-chat and giving forRoot a shot? If that works all good we could release a patch with the changes.

@Inexad
Copy link
Author

Inexad commented Oct 14, 2019

Sorry for late reply @rpaschoal . Yes, that is maybe something i can do. I will have a look at it when i got some time over.

@rejahrehim
Copy link

Stuck with the same issue. Waiting for the patch.

@rpaschoal
Copy link
Owner

I'm running short on time these days but will be looking closely if @Inexad gets to push a fixing patch for it via a pull request.

@shakthi-manai
Copy link

shakthi-manai commented Nov 12, 2019

Hello, I am having an issue using ng-chat in angular 8 based application .
The error is given below.
ng-chat.js:477 ng-chat component couldn't be bootstrapped.
ng-chat.js:485 An exception has occurred while initializing ng-chat. Details: Cannot read property 'pipe' of undefined
TypeError: Cannot read property 'pipe' of undefined
at NgChat.fetchFriendsList (ng-chat.js:555)
at NgChat.activateFriendListFetch (ng-chat.js:503)
at NgChat.bootstrapChat (ng-chat.js:463)
at NgChat.ngOnInit (ng-chat.js:421)
at checkAndUpdateDirectiveInline (core.js:31909)
at checkAndUpdateNodeInline (core.js:44366)
at checkAndUpdateNode (core.js:44305)
at debugCheckAndUpdateNode (core.js:45327)
at debugCheckDirectivesFn (core.js:45270)
at Object.eval [as updateDirectives] (DashboardComponent.html:61).

Any help would be appreciated. Thanks in advance

@rpaschoal
Copy link
Owner

With the package now running on Angular 9, could any of you confirm this is still an issue? @Inexad @rejahrehim

@Theinfinix500
Copy link

we are facing the same issue. the ngchatModule resets the interceptor configuration. we will appreciate if you could remove the HttpClientModule from the imports of the library and let the developers add it to there modules.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants