Creating an auth service
We will start by creating the abstract auth service and the in-memory service:
- Add an auth service:
$ npx ng g s auth --flat false $ npx ng g s auth/inMemoryAuth --skip-tests
- Rename
in-memory-auth.service.ts
toauth.in-memory.service.ts
so that the different auth providers visually group together in File Explorer. - Remove the
@Injectable()
decorator ofauth.service.ts
, but keep it onauth.in-memory.service.ts
. - Ensure that
authService
is provided inapp.module.ts
and thatInMemoryAuthService
is used and not the abstract class:src/app/app.module.ts import { AuthService } from './auth/auth.service' import { InMemoryAuthService } from './auth/auth.in-memory.service' ... providers: [ { provide: AuthService, useClass: InMemoryAuthService }, ... ]
Creating a separate folder for the service organizes various components related to auth, such as the enum...