Reader small image

You're reading from  Angular for Enterprise Applications - Third Edition

Product typeBook
Published inJan 2024
Reading LevelExpert
PublisherPackt
ISBN-139781805127123
Edition3rd Edition
Languages
Right arrow
Author (1)
Doguhan Uluca
Doguhan Uluca
author image
Doguhan Uluca

Doguhan Uluca is a Principal Fellow at Excella in Washington, D.C., where he leads strategic initiatives and delivers critical systems. He has technical expertise in usability, mobility, performance, scalability, cybersecurity, and architecture. He is the author of the Angular for Enterprise Application Development books, has spoken at over 30 conferences, and is an Angular GDE Alumni. Doguhan has delivered solutions for Silicon Valley startups, Fortune 50 companies, and the U.S. Federal Government, and he is passionate about contributing to open-source projects and teaching.
Read more about Doguhan Uluca

Right arrow

Creating an auth service

We will start by creating the abstract auth service and the in-memory service:

  1. Add an auth service:
    $ npx ng g s auth --flat false
    $ npx ng g s auth/inMemoryAuth --skip-tests
    
  2. Rename in-memory-auth.service.ts to auth.in-memory.service.ts so that the different auth providers visually group together in File Explorer.
  3. Remove the @Injectable() decorator of auth.service.ts , but keep it on auth.in-memory.service.ts.
  4. Ensure that authService is provided in app.module.ts and that InMemoryAuthService 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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Angular for Enterprise Applications - Third Edition
Published in: Jan 2024Publisher: PacktISBN-13: 9781805127123

Author (1)

author image
Doguhan Uluca

Doguhan Uluca is a Principal Fellow at Excella in Washington, D.C., where he leads strategic initiatives and delivers critical systems. He has technical expertise in usability, mobility, performance, scalability, cybersecurity, and architecture. He is the author of the Angular for Enterprise Application Development books, has spoken at over 30 conferences, and is an Angular GDE Alumni. Doguhan has delivered solutions for Silicon Valley startups, Fortune 50 companies, and the U.S. Federal Government, and he is passionate about contributing to open-source projects and teaching.
Read more about Doguhan Uluca