message: Make JWT parsing failsafe for invalid/undefined tokens
diff: @@ -3,6 +3,40 @@ import * as jwt_decode from 'jwt-decode'
  import { roles } from './roles'
  import { Injectable } from '@angular/core'
  +@Injectable()
  +export class LoginGuard implements CanActivate {
  + constructor (private router: Router) {}
  +
  + canActivate () {
  + if (localStorage.getItem('token')) {
  + return true
  + } else {
  + this.forbidRoute('UNAUTHORIZED_ACCESS_ERROR')
  + return false
  + }
  + }
  +
  + forbidRoute (error = 'UNAUTHORIZED_PAGE_ACCESS_ERROR') {
  + this.router.navigate(['403'], {
  + skipLocationChange: true,
  + queryParams: { error }
  + })
  + }
  +
  + tokenDecode () {
  + let payload: any = null
  + const token = localStorage.getItem('token')
  + if (token) {
  + try {
  + payload = jwt_decode(token)
  + } catch (err) {
  + console.log(err)
  + }
  + }
  + return payload
  + }
  +}
  +
  @Injectable()
  export class AdminGuard implements CanActivate {
  constructor (private loginGuard: LoginGuard) {}
  @@ -42,33 +76,3 @@ export class DeluxeGuard {
  return payload && payload.data && payload.data.role === roles.deluxe
  }
  }
  -
  -@Injectable()
  -export class LoginGuard implements CanActivate {
  - constructor (private router: Router) {}
  -
  - canActivate () {
  - if (localStorage.getItem('token')) {
  - return true
  - } else {
  - this.forbidRoute('UNAUTHORIZED_ACCESS_ERROR')
  - return false
  - }
  - }
  -
  - forbidRoute (error = 'UNAUTHORIZED_PAGE_ACCESS_ERROR') {
  - this.router.navigate(['403'], {
  - skipLocationChange: true,
  - queryParams: { error }
  - })
  - }
  -
  - tokenDecode () {
  - let payload: any = null
  - const token = localStorage.getItem('token')
  - if (token) {
  - payload = jwt_decode(token)
  - }
  - return payload
  - }
  -}
  