Devemos preparar e proteger o máximo a nossa interface
Porém ela é a primeira defesa, não a única.
Atributos importantes:
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { AuthService } from './auth.service';
@Injectable()
export class AuthGuardService implements CanActivate {
constructor(public auth: AuthService, public router: Router) {}
canActivate(): boolean {
if (!this.auth.isAuthenticated()) {
this.router.navigate(['login']);
return false;
}
return true;
}
}
@NgModule({
...
imports: [
...
HttpClientXsrfModule.withOptions({
cookieName: 'csrf-token',
headerName: 'csrf-token'
})
],
...
bootstrap: [AppComponent]
})