0

On login the backend (Drupal) provides users' details as well as a session, after refresh the user is still logged in but angularJS lose users data !!
I thought about cookies storage or web storage to maintain it.
I want to store the the user_id, username and some other informations.
How can I do that?
What is the best way?

Destrif
  • 1,926
  • 1
  • 11
  • 22
Mehdi Guelloub
  • 376
  • 2
  • 4
  • 17

1 Answers1

0

You can use cookies with this:

https://docs.angularjs.org/api/ngCookies

Or some external API that facilitate html5/local storage:

https://github.com/grevory/angular-local-storage

http://ngmodules.org/modules/ngStorage

They all seem pretty straightforward with plenty of examples on how to use.

  • Thank you @wdanda but i wanted to know 2 things: 1- Is it right to store those informations like that, so everyone can see them? 2- What is better way? Cookies or webStorage? – Mehdi Guelloub Jun 14 '16 at 13:10
  • @MehdiGuelloub There is a nice explanation of the differences between the two: http://stackoverflow.com/questions/3220660/local-storage-vs-cookies. If you are okay with using html5, you'd probably be better off using local storage as it doesn't send it back to the server on every postback (cookies are sent via http headers). And security wise, either can only be seen by the user's browser so storing it is okay for storing non-sensitive information. Another approach I've used was to have the server side return a variable in the html that is passed to angular as a constant. – Wagner Danda da Silva Filho Jun 14 '16 at 13:41