An in-memory auth service
Now, let’s implement a concrete version of the auth service that we can use:
- Start by installing a JWT decoding library and, to fake authentication, a JWT encoding library:
$ npm install fake-jwt-sign
- Extend the abstract
AuthService
:src/app/auth/auth.in-memory.service.ts import { AuthService } from './auth.service' @Injectable({ providedIn: 'root' }) export class InMemoryAuthService extends AuthService { constructor() { super() console.warn( 'You're using the InMemoryAuthService. Do not use this service in production.' ) } … }
- Implement a fake
authProvider
function that simulates the authentication process, including creating a fake JWT on the fly:src/app/auth/auth.in-memory.service.ts import { sign } from 'fake-jwt-sign'//For InMemoryAuthService only ... protected authProvider( email: string, password...