Implement a basic authentication service

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:

  1. 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
  1. 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 ...

Get Building Large-Scale Web Applications with Angular now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.