how to set up ngx admin to prevent pages without login

377 views Asked by At

I would like to try Ngx Admin. I customized the login form successfully and I also wanted to set up to prevent access pages without login. The last one cannot work at all.

I followed this :https://akveo.github.io/nebular/docs/auth/custom-auth-components#login-component-extension What I realized my AuthGuard always return true somehowe and the pages/* is always available without login:

  constructor(private authService: NbAuthService, private router: Router) {
    }

  canActivate() {
    console.log("canActivate is running");
    console.dir(this.authService.isAuthenticated());
    return this.authService.isAuthenticated()
    .pipe(
      tap(authenticated => {
        console.log("Always true??? "+ authenticated);
        if (!authenticated) {
          this.router.navigate(['auth/login']);
        }
      }),
    );
  }

I am totaly new in Angular and ngx admin but I hope you can help on this what should I check. I have no any backend so I would like to use a dummy beckend and configure for that but I could not find any useful and detailed article. Could you help me please?

0

There are 0 answers