I am developing a single-page application. The page has a toolbar. When the user clicks on any button, it visually creates a tab, and triggers an ajax request to the required controller. Now two things: firstly, the user always has to be authenticated, and secondly, not every user has access to each functionality. In the first draft of this application, I didn't have much time to think about it, and I wrote a Javascript function whose body mainly was a Switch structure calling the right controller based on which button was clicked. I'm no web developer, but I feel this solution is bad for at least three reasons:
- The most obvious: I have one more file to modify if I change or add some controller.
- This reveals the URL of all the existing controllers to anyone that reads the code of the page.
- I have to do the same security checks in every controller.
I imagined the following scenario... what if, after authentication, I only had one controller that checks if the requested functionality is available for the connected user, and only then calls the right code (controller? simple class?) and return the result of this code. This code would never be accessible from outside, only internally.
Am I just confused with MVC and the SPA pattern?