Configure JwtModule in an NgModule-based application
mainTo use the SDK in a traditional Angular application, import JwtModule and HttpClientModule. Use JwtModule.forRoot() to provide a configuration object containing:
tokenGetter: A function that returns the JWT string (e.g., fromlocalStorage).allowedDomains: An array of domains where the token should be attached.disallowedRoutes: An array of specific routes where the token should NOT be attached.
import { JwtModule } from "@auth0/angular-jwt";
import { HttpClientModule } from "@angular/common/http";
export function tokenGetter() {
return localStorage.getItem("access_token");
}
@NgModule({
bootstrap: [AppComponent],
imports: [
// ...
HttpClientModule,
JwtModule.forRoot({
config: {
tokenGetter: tokenGetter,
allowedDomains: ["example.com"],
disallowedRoutes: ["http://example.com/examplebadroute/"],
},
}),
],
})
export class AppModule {}