How to protect my code in Angular2?

Imagine that the application has a heavy admin interface with great features and a simple user interface like a single button. I know that I can restrict access to my URLs (components) based on something (key, hash, or something else). I want to achieve: If the backend decides that I am a regular user, it sends only a small application (for example, with only one component with a button), and the user does not receive all the code for heavy components (for all functions of the site). Therefore, it will not be able to parse my javascript. If the backend is deid, I am the staff - the front-end should get all the necessary components for the staff. If I am an administrator, I should get all the components.

+5
source share
1 answer

Questions:

Do you really need this?

The general scheme is to send the whole js of the linked file (you can trick it, reduce it, etc.), but it will still contain the templates and the code that you implemented. In most cases, this is not a problem, because in fact there is no confidential data. The point is to properly protect REST API endpoints.

If you really wanted

You can use for example. webpack or any other binding system that allows you to create separate packages and download the correct piece of code only when necessary (for example, after successful login). Here you download async for webpack . This resource will be protected by the hosting server (an authorized user will be required - just like REST API calls).

+3
source

All Articles