angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

@auth0/angular-jwt tokenGetter can't resolve in module

Open coskuntekin opened this issue 9 years ago • 2 comments

JwtModule.forRoot({
      config: {
        tokenGetter: () => {
          return localStorage.getItem('access_token');
        },
        whitelistedDomains: ['localhost:3001']
      }
    })

i have been add this line in app.module.ts but on first run (ng serve) i am getting error.

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 30:22 in the original .ts file), resolving symbol AppModule in ..../src/app/app.module.ts

And error line is tokenGetter.

coskuntekin avatar Jul 19 '17 04:07 coskuntekin

Looking at the error message I suggest you to try the following solution.

  export function getToken() {
   return localStorage.getItem('access_token');
  }

  JwtModule.forRoot({
      config: {
        tokenGetter: getToken,
        whitelistedDomains: ['localhost:3001']
      }
    })

lekhnath avatar Jul 21 '17 08:07 lekhnath

@lekhnath damn. Thank you so much. Sometimes missing. Thank you again.

coskuntekin avatar Jul 21 '17 09:07 coskuntekin