I am a newbie to MEAN stack and developing an end-to-end application using MEAN. I have a small confusion on how to handle authentication tokens on client side (i.e. in Angularjs).
I created an authentication token after either the user signup's or login to the application. I followed this link for creating authentication token. I set the authentication token in response headers and saving it on the browsers localStorage on client side. I accessed it whenever i did a REST call.
Is it a good practice to access tokens directly from the localStorage or i need to access the token by creating either a factory or a service ?. I have seen many SO answers, in which they access the tokens by creating either a factory or a service, but my confusion is if i can able to access the token straight away from localStorage why i need to create a factory or service ? Is there any best practices for it ?