Auth0 broken in latest @ionic/storage implementation

so the last known example ( showed doing this in app.module.ts

import {Storage} from "@ionic/storage";

let storage: Storage = new Storage();

export function getAuthHttp(http: Http) {
    return new AuthHttp(new AuthConfig({
        globalHeaders: [{'Accept': 'application/json'}],
        tokenGetter: (() => storage.get('id_token'))
    }), http);

which throws the error Supplied parameters do not match any signature of call target. on the new Storage line.

is there a way around this? I tried doing many different approaches but how can I get a valid ref to storage in that function?

ok I was able to use it by moving my code to a separate file ( I just put it in my AuthService)
this will not work in app.module.ts

then appending it in this fashion

export function AuthHttpServiceFactory(http: Http, options: RequestOptions) {
    let _storage = new Storage({});
    return new AuthHttp(new AuthConfig({
        noJwtError: true,
        tokenGetter: (() => _storage.get('id_token')),
        globalHeaders: [{'Content-Type':'application/json'}],
    }), http, options);

You should not be directly instantiating Storage (or virtually anything else in an Angular app). Use DI the same way you are doing so for Http.

1 Like

I agree, except when I did it that way, storage is undefined
and when I wrap it with a storage.ready().then(() => {
then I get in a nasty loop

Are you sure you included its module as described here?

yes, it works perfectly for other things, I suspect it is a timing thing as the AuthHttpServiceFactory is getting wired in the app.module.ts right away

The solution suggested in angular2-jwt #323 is better than what you are doing.

agreed, that seems to work better. was looking for awhile and hadn’t seen that yet.