#Storing session data

7 messages · Page 1 of 1 (latest)

crisp ridge
#

hi guys, is there a recommended way in angular to store session data ? Like the username, the role of the user and stuff of that sort ? I come from Vue and there we use a store, which lives for the entire lifecycle of the webapp and you can save and retrieve data from there
i see there's NgRx, but is that the actual correct solution to use ? Is there a more conventional way of doing it ?

hushed dagger
#

I've personally haven't used NgRx yet, all I know is that it is a very nice solution for quite complex application. If your goal is to store session data, you could declare your own UserService or AuthService where you have the username: string, role: RoleEnum, and many more properties which you can obtain by injecting that User/AuthService into your component and referencing those keys.

crisp ridge
#

makes sense, to persist the data i would save to LocalStorage, right ?

hushed dagger
#

One common pattern for storing state is to use Subjects or BehaviourSubjects from rxjs

crisp ridge
#

thank you for your answer, you've been very helpful

#

i'll leave the thread open in case someone wants to add value to this