Here is my module declaration with a service:
import { ConnectionService } from './services/connection.service';
import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig({
tokenName: 'token',
tokenGetter: (() => sessionStorage.getItem('token'))
}), http, options);
}
@NgModule({
providers: [
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions]
}
],
})
export class AuthModule { }
The service looks like this:
import { Injectable } from '@angular/core';
@Injectable()
export class ConnectionService {
id;
getToken() {
return JSON.parse(sessionStorage.getItem('token'))[this.id];
}
}
I am trying to utilize the "getToken" method from the service in the "tokenGetter" of the module's exported function, but I am struggling to get it to work. I have searched on Google for a solution without success so far.