import { Injectable } from '@angular/core' ; import { Router } from '@angular/router' ; import { Observable , pipe , throwError } from 'rxjs' ; import { map , tap } from 'rxjs/operators' ; import decode from 'jwt-decode' ; @ Injectable ( { providedIn : 'root' } ) export class AuthService { private message : string ; constructor ( private _router ) { } /**
     * this is used to clear anything that needs to be removed
     */ clear ( ) { localStorage . clear ( ) ; } return { boolean } isAuthenticated ( ) { return localStorage . getItem ( 'token' ) != null && ! this . isTokenExpired ( ) ; } isTokenExpired ( ) { return false ; } loginAdmin ( ) { localStorage . setItem ( 'token' , `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE1MzMyNzM5NjksImV4cCI6MTU2NDgxMDAwNSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiVGVzdCBHdWFyZCIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJyb2xlIjoiQWRtaW4ifQ.rEkg53_IeCLzGHlmaHTEO8KF5BNfl6NEJ8w-VEq2PkE` ) ; this . _router . navigate ( [ '/dashboard' ] ) ; } login ( ) { localStorage . setItem ( 'token' , `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE1MzMyNzM5NjksImV4cCI6MTU2NDgxMDAwNSwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoiVGVzdCBHdWFyZCIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20ifQ.GA0Y9gYIjmx1jLwuRHuBgZ8m6o-NgkD84nO0ym68CWo` ) ; this . _router . navigate ( [ '/dashboard' ] ) ; } /**
     * this is used to clear local storage and also the route to login
     */ logout ( ) { this . clear ( ) ; this . _router . navigate ( [ '/login' ] ) ; } decode ( ) { return decode ( localStorage . getItem ( 'token' ) ) ; } }