After updating to 0.1.25 from 0.1.24 my requests simply stopped sending. The observable error didn't have anything useful in it (message = "", name = "Error" 馃槶 ).
I had tokenName overriden to "token" in the provideAuth config. After setting the tokenGetter option to:
() => localStorage.getItem('token')
everything worked again. I don't believe tokenName is being used in 0.1.25.
can you repro in a plunk?
As is, the get request will not occur. Uncomment line 41 in src/app.ts and request will happen. This is speculation, but it seems like it's not finding the token and then not sending the request because the "token" is invalid.
Thanks for the repro. For now you'll be stuck with the workaround you've come up with. The problem is with how we construct the authconfig object. I'll have to re-evaluate that and fix it up.
Any news on this issue?
I haven't had time to work on it myself. It's due to how the constructor for authConfig was refactored between 1.24 and 1.25. I don't really want to revert what's there, but it should be something we can resolve without doing so. Contributions are welcome.
@escardin - any progress on this?
This should be resolved in 0.1.28. Please reopen if that is not the case.
It does not see to be resolved in 0.1.28. If I revert to not using a custom token name, there's no AuthHttpError
@parliament718
I forked my original repro, but pointed it at 0.1.28... it seems to work as expected now. Your issue may be elsewhere:
Perhaps an old version in node modules?
@parliament718 Did you get this fixed? I would like to close it.
Hello, I was led here after some googling and reading just about every issue open in the repo. I was getting the "No JWT present or has expired", with the following:
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
return new AuthHttp(new AuthConfig({
tokenName: 'token',
tokenGetter: (() => sessionStorage.getItem('token')),
globalHeaders: [{'Content-Type':'application/json'}],
noTokenScheme: true
}), http, options);
}
After seeing @mwaltersva's plnkr, I noticed that the tokenGetter line was commented out. Sure enough after I commented out that line, everything was working as it should.
I am not sure if this was "fixed", but I nearly pulled my hair out following the documentation and using the tokenGetter line in my NG2 app. I am on version: "angular2-jwt": "^0.1.28"
If you need any more information to help resolve this, please let me know.
the token getter you've defined is using session storage. by default, if you don't provide a getter, we'll use the token name you passed to make one that fetches from local storage (not session storage). If you don't provide a token name either, we'll use the default there as well.
Oh my god, I overlooked such a simple thing. What you just explained makes complete sense. I must have overlooked it last night while I was tired. Thank you for the explanation.
Most helpful comment
Thanks for the repro. For now you'll be stuck with the workaround you've come up with. The problem is with how we construct the authconfig object. I'll have to re-evaluate that and fix it up.