I am developing an application for which I have a user area and an administration area. I split them into separate Angular 2 modules. I successfully performed lazy loading so that the user module can only be loaded when the user asks for "/ admin".
From the Angular 2 documentation, I see that I can specify the "canLoad" protection like this:
{ path: 'admin', loadChildren: 'app/admin/admin.module#AdminModule', canLoad: [AdminGuard] }
and implement the canLoad function inside the AdminGuard class as follows:
canLoad(route: Route): boolean { return this.authService.isAdmin(); }
(where isAdmin () can make an API call to the backend, which will return the role of the current user or something like that)
But does this really prevent the AdminModule from loading by the non-administrator? If I'm not mistaken, all this code is on the client, so is there something that can prevent the client from modifying the "canLoad" method so that it always returns true? For instance:
canLoad(route: Route): boolean { return true; }
Thus, the client can download any module that they need.
Obviously, any backend API calls that require administrator status will be protected, but it seems that any user will be able to view the admin user interface, which seems a little strange to me. Can someone clarify this for me?
source share