# Auth http: No JWT present or has expired

**URL:** <https://community.auth0.com/t/auth-http-no-jwt-present-or-has-expired/8417>\
**Category:** Get Help\
**Tags:** auth, jwt, ionic2\
**Created:** [October 7, 2017, 8:24pm UTC](https://community.auth0.com/t/auth-http-no-jwt-present-or-has-expired/8417 "2017-10-07T20:24:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![me7](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@me7](https://community.auth0.com/u/me7)\
**Post date:** [October 7, 2017, 8:24pm UTC](https://community.auth0.com/t/auth-http-no-jwt-present-or-has-expired/8417/1 "2017-10-07T20:24:03Z")

</div>

I know there is a lot on different forums on this issue. I looked here, on ionic forum and on stackoverflow.

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, above @ngmodule I have an getAuthHttp function:

```
export function getAuthHttp(http) {
    return new AuthHttp(new AuthConfig({
        headerPrefix: 'bearer',
        noJwtError: true,
        globalHeaders: {'Accept': 'application/json'}],
        tokenGetter: (() => JSON.parse(window.localStorage.getItem('id_token'))),
    }), http);
}

```

(I tried to fix tokengetter by getting token from localstorage instead of creating new storage as is suggested in some official documentation)

this is my providers array:

```
providers: 
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    {provide: AuthHttp, useFactory: getAuthHttp, deps: [Http] },
    AUTH_PROVIDERS,
    ChallengeService, SettingsService, UserdataService, AuthService
  ]

```

and of course I have an authservice file which handles login and logout and probaly more which I don’t use at the moment.

My service which calls the api:

```
import { Injectable} from '@angular/core';
import { AuthService} from "./auth.service";
import { AuthHttp } from "angular2-jwt";
import 'rxjs/Rx';

@Injectable()
export class MessageService{

    http: any;
    messages: any;
    authService: any;
    
    constructor(authService:AuthService, private authHttp:AuthHttp){
        this.storage = storage;
        this.authService = authService;
        this.authHttp = authHttp;
    }

    getMessage(level, location)
    {
        this.messages= this.authHttp.get('http://10.0.2.2:8080/api/message/1');
        return this.messages;
    }
};

```

Now this goes wrong, obviously.

I 'm pretty sure i’m forgetting something but i can’t pinpoint it and after days of getting closer now i’m totally stuck. Who can help me fix this? I would also be okay with just using angular http but I cannot get it working with sending the headers myself as well.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:56am UTC](https://community.auth0.com/t/auth-http-no-jwt-present-or-has-expired/8417/2 "2018-03-02T05:56:52Z")

</div>


