1

I will try to phrase this question more as a problem than a discussion point.

Im building an Angular 4 + Spring application and I am having problems with state management. App functionalities are login, interactive map, subpages with settings etc.

My problem: For example, user logs in, does something with interactive map(changes map layers which are shown or zooms in on map) and then goes to an subpage or logs off completely from app. The desired functionality would be that next time the user logs in, the same things that he/she did last time will be there also this time.

I have done some research and currently I see 3 options:

  1. Front-end approach with cookies
  2. Back-end approach with API's that hold these values
  3. Redux

At this point I'm not sure which approach I should take..

raouaoul
  • 681
  • 2
  • 13
  • 33
  • The comment **"next time the user logs in"** is a bit unclear, do you mean if the user logs in let's say two weeks from now? – AT82 Mar 07 '18 at 11:23
  • @Alex could be ten minutes, could be two weeks. In which case this would matter? I can only imagine cookies/localstorage expiration. – raouaoul Mar 07 '18 at 11:39
  • Well it would matter, what if local storage is cleared in between? What if user logs in from another computer? Safest bet would be to utilize the backend then (?), but it depends on your case of course. I was a bit unclear with my initial question, sorry bout that :) – AT82 Mar 07 '18 at 11:43
  • 1
    Okay yes true, thats a good point. Thanks! – raouaoul Mar 07 '18 at 11:59

1 Answers1

1

If you want to store the data for the user permanently, the easiest way is to put them into the localStorage of the browser. This way you can retrieve the users data when your components is loading. To do this you simply do this:

//Put data to local storage
localStorage.setItem('userData', JSON.stringify(data));

//Get data from local storage
let userData = JSON.parse(localStorage.getItem('userData'))

The problem with a redux approch is, if you reload your application your savings will be gone.

Also an approach that involves the backend is not the best idea. Because you have extra calls to the backend, need new tables to hold the data for each user etc.

ochs.tobi
  • 3,214
  • 7
  • 31
  • 52