so I am using a simple authguard to redirect me to the login page when there's no session, but it only works when I refresh the page!
my routing module:
const routes: Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuardService] },
{ path: 'login', component: LoginComponent },
{ path: 'logout', component: LogoutComponent, canActivate: [AuthGuardService] }
];
my authguard:
export class AuthGuardService implements CanActivate {
constructor(private router: Router,
private authService: AuthenticationService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.authService.isUserLoggedIn())
return true;
this.router.navigate(['login']);
return false;
}
}