Auth Service

Let's create an authentication service that will only redirect logged-in users to the dashboard.

We left off the last chapter with an issue related to our user dashboard. Our dashboard should only be viewable to users who are logged in. If they aren’t, they should be redirected to another view, such as /signup or /login instead.

To do this, we’ll create a route guard within Angular.

AuthGuard setup

First, we’ll create a guard within a new directory for our route guards.

ng g guard guards/auth/auth

Get hands-on with 1200+ tech skills courses.