How to pass dependencies to @auth0-angular-jwt?

。_饼干妹妹 提交于 2019-12-06 08:51:19

This can be done by overriding config service:

export const jwtOptionsFactory = (dependency) => ({
    tokenGetter: () => dependency.getToken(),
    whitelistedDomains: []
});

...
imports: [
    JwtModule.forRoot({
        config: { tokenGetter(): string { throw new Error('no tokenGetter') } }
    })
],
providers: [{
    provide: JWT_OPTIONS,
    deps: [Dependency],
    useFactory: jwtOptionsFactory
}]

Starting from 1.0.0-beta.8, forRoot accepts options provider:

...
imports: [
    JwtModule.forRoot({
        jwtOptionsProvider: {
            provide: JWT_OPTIONS,
            deps: [Dependency],
            useFactory: jwtOptionsFactory
        }
    })
]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!