Skip to content

Invalid JWT token in local storage will crash App / NbAuthJWTToken  #517

Description

@schuettecarsten

Issue type

I'm submitting a ... (check one with "x")

  • bug report
  • feature request

Issue description

Current behavior:
When login response of a NbPasswordAuthStrategy returns an broken JWT token, it is stored in the local storage without validation. On the next request, the app will fail because NbAuthJWTToken cannot parse the token.

Expected behavior:
A broken token should be rejected during login.

Related code:
See the exception that occurs when token from login response is invalid:

ERROR Error: The token yeah! is not valid JWT token and must consist of three parts.
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getPayload (token.js:112)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getTokenExpDate (token.js:139)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.isValid (token.js:160)
    at MapSubscriber.project (auth.service.js:75)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:35)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at RefCountSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
    at RefCountSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at Subject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47)
    at ConnectableSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)

This exception is shown in Console log when the App tries to use the broken Token, the app crashes:

core.js:1601 ERROR Error: Uncaught (in promise): Error: The token yeah! is not valid JWT token and must consist of three parts.
Error: The token yeah! is not valid JWT token and must consist of three parts.
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getPayload (token.js:112)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getTokenExpDate (token.js:139)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.isValid (token.js:160)
    at MapSubscriber.project (auth.service.js:44)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:35)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at Observable._subscribe (scalar.js:5)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:42)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:28)
    at MapOperator.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapOperator.call (map.js:18)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getPayload (token.js:112)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.getTokenExpDate (token.js:139)
    at NbAuthJWTToken.push../node_modules/@nebular/auth/services/token/token.js.NbAuthJWTToken.isValid (token.js:160)
    at MapSubscriber.project (auth.service.js:44)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:35)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at Observable._subscribe (scalar.js:5)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:42)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:28)
    at MapOperator.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapOperator.call (map.js:18)
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at zone.js:873
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4062)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:500)
    at ZoneTask.invoke (zone.js:485)

Other information:

npm, node, OS, Browser

OS: Windows 10, Chrome

Angular, Nebular

Angular 6.0, Nebular 2.0.0-rc.9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions