question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No provider for AuthHttp! when it's provided correctly

See original GitHub issue

At least I thought I was providing correctly. Below are the relevant snippets of my app.module file and the service in which I use AuthHttp. I followed the configuration in the ReadMe for creating the factory method to provide for AuthHttp, but there is a persisting issue with it not being recognized in my service. I’ve read the literature on nested dependency injections, and I feel as though I’m doing things correctly.

app.module.ts

import { provideAuth, AuthHttp, AuthConfig } from 'angular2-jwt';

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig(), http, options);
}

@NgModule({
    declarations: [
        AppComponent,
        ButtonFormComponent,
...
imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        RouterModule,
        AppRoutingModule
    ],
    providers: [
        {
            provide: LocationStrategy,
            useClass: HashLocationStrategy
        },
        {
            provide: AuthHttp,
            useFactory: authHttpServiceFactory,
            deps: [Http, RequestOptions]
        },

employee.service.ts

import { AuthHttp } from 'angular2-jwt';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';

import { ApiSettings } from './api-settings';


@Injectable()
export class EmployeeService {
	api: String;
	auth: String;
	constructor(private http: Http, private authHttp: AuthHttp) {
		this.api = ApiSettings.API;
		this.auth = ApiSettings.Auth;
	}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:14

github_iconTop GitHub Comments

11reactions
morismaelcommented, Jan 27, 2018

I ran into the same issue and fought for days using Github and this repo. It turned out that the solution is very simple as I found on StackOverFlow: (https://stackoverflow.com/a/42064959):

In app.module.ts:

import { AUTH_PROVIDERS } from 'angular2-jwt';
...
providers: [AUTH_PROVIDERS, ...],

As simple as that!

5reactions
carl-angelocommented, Jul 5, 2017

You just have to import your auth.module in app.module.

app.module.ts

@NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, HttpModule, FormsModule, AuthModule // <----- Here is the auth.module class ], providers: [ AuthGuard, AlertService, AuthenticationService ], bootstrap: [AppComponent] })

export class AppModule { }

Read more comments on GitHub >

github_iconTop Results From Across the Web

No Provider for AuthHttp! Angular2-Jwt provider issue
I've read the literature on nested dependency injections, and I feel as though I'm doing things correctly. app.module.ts import { Http, ...
Read more >
[Solved]-angular2-jwt No provider for AuthConfig-angular.js
Coding example for the question angular2-jwt No provider for AuthConfig-angular.js. ... You have to provide all injected dependencies in your NgModule . add ......
Read more >
Auth http: No JWT present or has expired
When I'm trying to make an api call I get the response 401 (Unauthorized): No JWT present or has expired. in my app.module.ts,...
Read more >
How to fix No provider for HttpClient error in Angular
To fix NullInjectorError: No provider for HttpClient! follow the below steps 1. Open `app.module.ts` file 2. Import HttpClientModule from ...
Read more >
angular/angular - Gitter
no for real I don't know ... Because its provided by a DashboardModule that fails, but I also load ... or even comment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found