import { JwtModule, JwtHelperService } from '@auth0/angular-jwt';
then i am trying inside the constructor
constructor(
private http: Http,
private jwtHelperService: JwtHelperService
) { }
After i am getting this error in console
Error: StaticInjectorError(AppModule)[AuthService -> JwtHelperService]:
StaticInjectorError(Platform: core)[AuthService -> JwtHelperService]:
NullInjectorError: No provider for JwtHelperService!
Can you please help how to resolve.
That error is saying _"The module injecting your AuthService (AppModule) needs to provide a JwtHelperService to your AuthService."_
If you're trying to use Injection, make sure the module which provides your AuthService (AppModule) also provides a JwtHelperService. See https://github.com/auth0/angular2-jwt#usage-injection.
If you don't want injection, then you'll need to instantiate your helper service manually. See https://github.com/auth0/angular2-jwt#usage-standalone.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇♂️
I avoided this issue by NOT using constructor assignment.
import { JwtModule, JwtHelperService } from '@auth0/angular-jwt';
export class AuthService {
public jwtHelper: JwtHelperService = new JwtHelperService();
constructor(
private http: Http,
) { }
decodeToken() {
const token = localStorage.getItem('token');
return this.jwtHelper.decodeToken(token);
}
}
Yes, kittowned it worked for me.
Most helpful comment
I avoided this issue by NOT using constructor assignment.