Now, let's build a local authentication service that will enable us to demonstrate a robust login form, caching, and conditional navigation concepts based on authentication status and a user's role:
- Start by installing a JWT decoding library, and for faking authentication, a JWT encoding library:
$ npm install jwt-decode fake-jwt-sign$ npm install -D @types/jwt-decode
- Define your imports for auth.service.ts:
src/app/auth/auth.service.tsimport { HttpClient } from '@angular/common/http'import { Injectable } from '@angular/core'import { sign } from 'fake-jwt-sign' // For fakeAuthProvider onlyimport * as decode from 'jwt-decode'import { BehaviorSubject, Observable, of, throwError as observableThrowError ...