Custom SessionStorage For Angular Security

Baljinder Singh
The Startup
Published in
6 min readMar 3, 2020

--

Many of the web developers face challenges when a customer is more concerned about the security of the application. One such task is to handle session data without session storage. There are many ways to manage this feature in a Web Application. But let us discuss one of the ways which also suits best for a Single Page Application framework like Angular.

Following are the key modules we are going to use to accomplish this task :
1) Services — To maintain the session
2) Model/Pojo class — To store the session variables

The Mantra

As mentioned, the solution we are going to develop is based on Services in Angular. As Services are Singelton in nature, they maintain a single object in memory throughout the session of an Angular App. Consequently, all the variables of service would be available all the time until the session is alive.
The Model class would be one such variable of Service class. So, without any further wait lets dive into the code and see how it can be worth it.

1) SessionStorageModel

To begin with, we will create a Model class named SessionStorageModel. Here we will have a property as UserId of Model class just for reference to understand the concept. This would…

--

--

Baljinder Singh
The Startup

Keen to learn new technologies and contribute to the community to the best of my knowledge.