Angular - Guards

Here is a sample command

1
Ng generate guard auth

This will prompt you for which interface should be implemented? I chose CanActivate

There was a copy and paste which populated that class.
A guard can be added to routing

1
2
3
4
5
6
7
8
9
10
import { AuthGuard } from './auth.guard';

const routes: Routes = [
{ path: 'wikiedit/:wikiset/:title',
component:WikiEditComponent,
canActivate: [AuthGuard]
},
{ path: 'wikiview/:id',
component:WikiViewComponent },
:

Adding canActivate – will call the guard, and if the circumstances being tested within the guard is valid, then that path can be activated.

In my case I have a 3rd party validator (auth0), when you are logged in through this validator, then the Edit path becomes secured.