auth0/angular2-jwt

Extract and export JwtConfig from JwtModuleOptions

AlexAegis opened this issue · 1 comments

export interface JwtModuleOptions {
    jwtOptionsProvider?: Provider;
    config?: {
        tokenGetter?: (request?: HttpRequest<any>) => string | null | Promise<string | null>;
        headerName?: string;
        authScheme?: string;
        whitelistedDomains?: Array<string | RegExp>;
        blacklistedRoutes?: Array<string | RegExp>;
        throwNoTokenError?: boolean;
        skipWhenExpired?: boolean;
    };
}

The jwtOptionsProvider is such a function that returns an object like JwtModuleOptions.config. But there is no exported type for that.

When not using the provider, we get nice intelliSense from typescript, when using the provider this isn't the case. Sadly providers can't be typed, but we can type it ourselves.

extracting the config fields type into another interface, let's call it JwtConfig enables me to type the provider.

export const jwtOptionsFactory = (authStoreFacade: AuthStoreFacade): JwtConfig => ({
	tokenGetter: () => authStoreFacade.accessToken$.pipe(take(1)).toPromise(),
	whitelistedDomains: [environment.domain],
});

Pull request: #661

Fixed by #661, the fix will be included in the next release.