Add auth service

We will start by creating an auth service with a real and a fake login provider:

  1. Add an authentication and authorization service:
$ npx ng g s auth -m app --flat false
  1. Ensure that the service is provided in app.module:
src/app/app.module.tsimport { AuthService } from './auth/auth.service'...  providers: [AuthService],

Creating a separate folder for the service will organize various related components to authentication and authorization, such as the enum definition for Role. Additionally, we will be able to add an authService fake to the same folder, essential for writing unit tests.

  1. Define user roles as an enum:
src/app/auth/role.enum.tsexport enum Role {  None = 'none',  Clerk = 'clerk',  Cashier = 'cashier', Manager = ...

Get Angular 6 for Enterprise-Ready Web Applications 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.