Angular2-jwt: Please let us allow to provide JWT_OPTIONS so that we can use DI for our tokenGetter

Created on 27 Jul 2017  路  7Comments  路  Source: auth0/angular2-jwt

How am I supposed to use services in token getter. It was possible in previous version of this module but this newer version does not allow to do that. If we are allowed to provide config option as provider then this is doable. I was expecting to do following so that I could utilize services to provide token.

export function jwtOptionsProvider(store) {
  return {
    tokenGetter() {
      let token;
      store.select('authToken').select(1).subscribe(t => token = t);
      return token;
    };
  }
}

[
  {
    provide: JWT_OPTIONS,
    useFactory: jwtOptionsProvider,
    deps: [Store]
  }
]

Angular v 4.3.1
auth0/angular-jwt v^1.0.0-beta.5

Most helpful comment

The tokenGetter is currently set up to handle a returned string value synchronously, however, support for async token fetching is coming 馃憤

All 7 comments

The tokenGetter is currently set up to handle a returned string value synchronously, however, support for async token fetching is coming 馃憤

I see this was fixed in beta.6 by exporting JWT_OPTIONS token, although forRoot requires to provide dummy tokenGetter before it will be overridden with JWT_OPTIONS provider. Not very convenient. forRoot should likely be made optional, so it would be possible to configure a module with

imports: [JwtModule],
providers: [{ provide: JWT_OPTIONS, useFactory: ... }]

too.

What do you think, @chenkie ?

It might go that way. We also need to handle async token getters in the interceptor so it's not quite there yet.

Fixed in 1.0.0-beta.8. The readme has details.

@chenkie There's still a type problem, config property is required even when jwtOptionsProvider is specified.

Just merged a PR to fix and published 1.0.0-beta.9

@chenkie Great, just in time, thanks for the notification.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaumard picture jaumard  路  5Comments

leosvelperez picture leosvelperez  路  5Comments

n0490b picture n0490b  路  4Comments

getglad picture getglad  路  5Comments

sfabriece picture sfabriece  路  4Comments