Best practice to manage state in Angular 2/4/6 application

Viewed 990

I am new to angular but an project has been assigned to me so i've started working on it but i am facing a situation related to state management so after authentication through wcf Restful service an Token is provided to user. so i can handle this with these 3 approaches.

  • Session-storage

  • Cookies

  • local storage

    The problem with above approaches are --

  • if i use session state it will not valid for new tab in a browser so i can't check if the token is exist or not

  • if i use of local storage it won't work if user closes browser and get away from his/her system and later on someone else open his browser then it will be obviously a security threat.

  • if i use of cookies it was working fine till now until i face an weird issue my child component was being authenticated through authguard by using of canActivateChild function. but when i pasted the url (along with child component path) in a new tab then both page were same in both tab and when i clicked on Log out button from second tab it was not removing the cookies.

Note: function is being called each time i click on log out button but it is not working in second tab and from first tab it works fine.

1 Answers

The best approach will be Ngrx , if you are in Angular, Previously it was Redux. Now we have Ngrx also you can use Ngrx device tools as chrome extension to see the state and action when your application will load.. it's awesome.

Related