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.ts
import { 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.ts
export enum Role {
None = 'none',
Clerk = 'clerk',
Cashier = 'cashier',
Manager = 'manager',
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.60.158