P
P
Pogran2016-12-05 14:53:38
Angular
Pogran, 2016-12-05 14:53:38

How to display the error No permissions?

i have this router

{
        path: 'login',
        component: LoginLayoutComponent,
     
    },
  {
        path: 'dashboard',
        component: MainLayoutComponent,
        canActivate: [AuthGuard],
        data: { role: 'admin' },
    },

And AuthGuard with the canActivate method.
canActivate(route: ActivatedRouteSnapshot) {
        let user : User = this.userService.getCurrentUser();
        let role = route.data['role'];

        //console.log(route.url[0].path);

        if(user.role == role) {
            return true;
        } else {
            if(permissionDependence[user.role][role]) {
                return true;
            } else {
                //this.router.navigate(['/permission/'])
            }
        }

        // not logged in so redirect to login page
        this.router.navigate(['/login']);
        return false;
    }

How can I make it throw an error if there are no rights? And then nothing happens to me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question