title: Save user object in Session Storage
body: <p>I am using Angular 2 and Typescript and wanted to save the user object like a global variable so it hasn't to be retrieved multiple times. I found the session storage and now save the user object there. </p>
  
  <p>Do you think it is good practice to store it there or is the data too sensitve? If so, what other kind of cache could I use?</p>
  
  <p>Here is the code I use right now:</p>
  
  <p>user.service.ts:</p>
  
  <pre><code>getProfile() {
      let cached: any;
      if (cached = sessionStorage.getItem(this._baseUrl)) {
          return Observable.of(JSON.parse(cached));
      } else {
          return this.http.get(this._baseUrl).map((response: Response) =&gt; {
              sessionStorage.setItem(this._baseUrl, response.text());
              return response.json();
          });
      }
  }
  </code></pre>
  
  <p>The getProfile() is called in the app.component when ngOnInit(). The user object is also needed in other components of the application.</p>