{"action":"created","issue":{"url":"https://api.github.com/repos/auth0/angular2-jwt/issues/554","repository_url":"https://api.github.com/repos/auth0/angular2-jwt","labels_url":"https://api.github.com/repos/auth0/angular2-jwt/issues/554/labels{/name}","comments_url":"https://api.github.com/repos/auth0/angular2-jwt/issues/554/comments","events_url":"https://api.github.com/repos/auth0/angular2-jwt/issues/554/events","html_url":"https://github.com/auth0/angular2-jwt/issues/554","id":345472022,"node_id":"MDU6SXNzdWUzNDU0NzIwMjI=","number":554,"title":"TypeError: Cannot read property 'split' of undefined (crashes site on logout)","user":{"login":"gethinoakes","id":3785292,"node_id":"MDQ6VXNlcjM3ODUyOTI=","avatar_url":"https://avatars2.githubusercontent.com/u/3785292?v=4","gravatar_id":"","url":"https://api.github.com/users/gethinoakes","html_url":"https://github.com/gethinoakes","followers_url":"https://api.github.com/users/gethinoakes/followers","following_url":"https://api.github.com/users/gethinoakes/following{/other_user}","gists_url":"https://api.github.com/users/gethinoakes/gists{/gist_id}","starred_url":"https://api.github.com/users/gethinoakes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gethinoakes/subscriptions","organizations_url":"https://api.github.com/users/gethinoakes/orgs","repos_url":"https://api.github.com/users/gethinoakes/repos","events_url":"https://api.github.com/users/gethinoakes/events{/privacy}","received_events_url":"https://api.github.com/users/gethinoakes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-28T19:11:55Z","updated_at":"2018-07-28T19:29:39Z","closed_at":null,"author_association":"NONE","body":"Hi guys, this issue only occurs when the user is logged out and completely crashes the app. I get a bunch of errors about not being able to read 'split' of undefined.\r\n\r\n```\r\nAppComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'split' of undefined\r\n    at JwtHelperService.push../node_modules/@auth0/angular-jwt/src/jwthelper.service.js.JwtHelperService.decodeToken (jwthelper.service.js:70)\r\n    at JwtHelperService.push../node_modules/@auth0/angular-jwt/src/jwthelper.service.js.JwtHelperService.getTokenExpirationDate (jwthelper.service.js:83)\r\n    at JwtHelperService.push../node_modules/@auth0/angular-jwt/src/jwthelper.service.js.JwtHelperService.isTokenExpired (jwthelper.service.js:96)\r\n    at AuthService.push../src/app/core/auth/auth.service.ts.AuthService.isLoggedIn (auth.service.ts:124)\r\n```\r\n\r\nAs I said, this only happens when the user logs out but completely crashed the app so they can't log back in.\r\n\r\nHere's how JWT is implemented, it's been this way for a few months and nothing's changed so I have no idea what is going on here.\r\n\r\napp.module.ts\r\n```\r\nexport function tokenGetter() {\r\n  const user = JSON.parse(localStorage.getItem('user'));\r\n  const userToken = user ? user.token : null;\r\n  return userToken;\r\n}\r\n\r\n...\r\n\r\nJwtModule.forRoot({\r\n  config: {\r\n    tokenGetter: tokenGetter,\r\n    whitelistedDomains: ['localhost:4200']\r\n  }\r\n}),\r\n```\r\n\r\n\r\nauth.service.ts\r\n```\r\nimport { JwtHelperService } from '@auth0/angular-jwt';\r\n\r\nconstructor(\r\n    private http: HttpClient,\r\n    private jwtHelper: JwtHelperService\r\n  ) {}\r\n\r\n...\r\n\r\nisLoggedIn() {\r\n  return this.jwtHelper.isTokenExpired() ? false : true;\r\n}\r\n```\r\n\r\nThe only way I can get back into the app to log back in is to comment out the return statement within the isLoggedIn function.\r\n\r\nAny help would be very much appreciated, thanks."},"comment":{"url":"https://api.github.com/repos/auth0/angular2-jwt/issues/comments/408630017","html_url":"https://github.com/auth0/angular2-jwt/issues/554#issuecomment-408630017","issue_url":"https://api.github.com/repos/auth0/angular2-jwt/issues/554","id":408630017,"node_id":"MDEyOklzc3VlQ29tbWVudDQwODYzMDAxNw==","user":{"login":"gethinoakes","id":3785292,"node_id":"MDQ6VXNlcjM3ODUyOTI=","avatar_url":"https://avatars2.githubusercontent.com/u/3785292?v=4","gravatar_id":"","url":"https://api.github.com/users/gethinoakes","html_url":"https://github.com/gethinoakes","followers_url":"https://api.github.com/users/gethinoakes/followers","following_url":"https://api.github.com/users/gethinoakes/following{/other_user}","gists_url":"https://api.github.com/users/gethinoakes/gists{/gist_id}","starred_url":"https://api.github.com/users/gethinoakes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gethinoakes/subscriptions","organizations_url":"https://api.github.com/users/gethinoakes/orgs","repos_url":"https://api.github.com/users/gethinoakes/repos","events_url":"https://api.github.com/users/gethinoakes/events{/privacy}","received_events_url":"https://api.github.com/users/gethinoakes/received_events","type":"User","site_admin":false},"created_at":"2018-07-28T19:29:39Z","updated_at":"2018-07-28T19:29:39Z","author_association":"NONE","body":"Ok so looking through some other issues and pull requests, it seems that `isTokenExpired()` doesn't handle null (expired) tokens... if I'm right in that assumption then isn't this method completely broken? By it's name it should return false if the token is null and/or expired. It's also not mentioned in the readme anywhere so I assume this is in fact a bug.\r\n\r\n#495 seems like it should have fixed this from the description, but for now and for anyone else seeing this issue this is how I fixed it:\r\n\r\n```\r\nisLoggedIn() {\r\n    const token = this.user ? (this.user.token ? this.user.token : null) : null;\r\n    return token ? (this.jwtHelper.isTokenExpired() ? false : true) : false;\r\n  }\r\n```"}}
{"actor":{"display_login":"gethinoakes"}}