Skip to content

Commit

Permalink
fixed jwt dynamic loading issue (#47)
Browse files Browse the repository at this point in the history
Signed-off-by: Eamon Bauman <eamon@eamonbauman.com>
  • Loading branch information
ebauman committed Mar 30, 2020
1 parent 8fd0507 commit 2f456c4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { HomeComponent } from './home/home.component';
import { HeaderComponent } from './header/header.component';
import { EventComponent } from './event/event.component';
import { HttpClientModule } from '@angular/common/http';
import { JwtModule } from '@auth0/angular-jwt';
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt';
import { LoginComponent } from './login/login.component';
import { environment } from 'src/environments/environment';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
Expand All @@ -26,8 +26,18 @@ import { ConfigurationComponent } from './configuration/configuration.component'
import { EnvironmentsComponent } from './configuration/environments/environments.component';
import { EditEnvironmentComponent } from './configuration/environments/edit-environment/edit-environment.component';

export function tokenGetter() {
return localStorage.getItem("hobbyfarm_admin_token");
export function jwtOptionsFactory() {
return {
tokenGetter: () => {
return localStorage.getItem("hobbyfarm_admin_token");
},
whitelistedDomains: [
environment.server.match(/.*\:\/\/?([^\/]+)/)[1]
],
blacklistedRoutes: [
environment.server.match(/.*\:\/\/?([^\/]+)/)[1] + "/auth/authenticate"
]
}
}

@NgModule({
Expand Down Expand Up @@ -58,14 +68,9 @@ export function tokenGetter() {
ClarityModule,
HttpClientModule,
JwtModule.forRoot({
config: {
tokenGetter: tokenGetter,
whitelistedDomains: [
environment.server.match(/.*\:\/\/?([^\/]+)/)[1]
],
blacklistedRoutes: [
environment.server.match(/.*\:\/\/?([^\/]+)/)[1] + "/auth/authenticate"
]
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory
}
}),
BrowserAnimationsModule
Expand Down

0 comments on commit 2f456c4

Please sign in to comment.