Currently, I am developing an angular application at my workplace that requires implementing permissions. The backend stores permissions as either 1 or 0, and the frontend queries a service to retrieve the user's permission. If the user lacks permission for a specific action, the corresponding button is disabled. After careful consideration, we concluded that the most effective solution would be to save the permission to session storage on application startup and retrieve it from there whenever necessary.
This approach works flawlessly once the application launches. Every page successfully reads the permission and disables the appropriate buttons. However, I encountered an issue during the initial launch of the application. Since the permission retrieval is an asynchronous process, the application continues to start up while waiting for the permission to be fetched. As the default permission is set to none, the first page displays a disabled button even after obtaining the permission due to being created before the asynchronous call. A manual refresh resolves this issue.
I have been exploring ways to either detect changes in session storage and update the initial component accordingly or ensure that the application waits for the permission retrieval process to complete before continuing the startup sequence. Any guidance on this matter would be greatly appreciated.
-Thank you