Issue with JwtHelperService in new implementation
See original GitHub issueIm not sure if the JwtHelperService can be used together with the Interceptor. I want to use it in another service I have the following issue.
Cannot instantiate cyclic dependency! JWT_OPTIONS (“[ERROR ->]”): in NgModule CoreModule
Settings
CoreModule
JwtModule.forRoot({
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory,
deps: [TokenHandler]
}
}),
TokenHandler (own class for jwt decode …)
constructor(private cookieService: CookieService, private jwtHelper: JwtHelperService) { }
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
NullInjectorError: No provider for JwtHelperService
This solved my issue, but since my implementation was in my auth service ... public jwtHelper: JwtHelperService = new JwtHelperService();
Read more >ASP.NET Core Authentication with JWT and Angular - Part 2
Before we start with the login implementation, we are going to create a new _interfaces folder, and inside a new login.model file:.
Read more >Client-side Application For JWT Refresh Token In Angular 13
Refresh tokens are the kind of tokens that can be used to get new access tokens. ... import { JwtHelperService } from '@auth0/angular-jwt'; ......
Read more >Angular(v14) JWT Access Token Authentication & Refresh ...
In this article, we are going to implement JWT(JSON Web Token) authentication in ... jwtService: JwtHelperService = new JwtHelperService(); ...
Read more >Using JWT with Spring Security OAuth - Baeldung
A practical deep-dive into how to implement logout in a Spring ... It issues JWT tokens by default, so there is no need...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the same issue, but I still don’t know how to resolve it.
I import the JwtModule with the forRoot() stuff in my main app.module like this:
The jwtOptionsFactory looks like this:
Both the JwtHelperService and the HttpClient get injected into the AuthService, because it implements the token refreshing logic, too.
The resulting error looks like this:
The AuthService is placed inside its own AuthModule, which is also included (with forRoot()) in the appModule. The JwtModule is only included in the AppModule though.
Oh another maybe useful info: I’m using my own (second) interceptor to handle token refresh logic, which depends on the AuthService, too.
Is there something I did wrong?
Hi all, FTR, I was facing the same issue, the problem is that we need to inject a service in the
jwtOptionsFactory
but this service is also provide in the moduleproviders
.it was tricky, maybe not the best, but I can solved the issue on that way:
app.module.ts
jwtOptions.factory.ts