How to create own service accessible globally that will call server by currentUser()
only once on page load, if User is logged in then keep it and provide data to c
I've had to deal with user Authentication in a large Angular app and found this article very useful: https://medium.com/opinionated-angularjs/techniques-for-authentication-in-angularjs-applications-7bbf0346acec
Specific to 'how to make it happen only once':
resolve
requirement of an outer state for the app (if you use nested states)A UserService
Service to represent user's logged in state works well for sharing state throughout the application. The login and logout functions can be exposed through this service and the user's details can be stored here too. Defining a UserApi
that extends $resource
will probably help too to separate the actual HTTP concerns from managing user state.
Other concerns that will catch you, both of which are covered in the article: persistent state across page refreshes, and having areas of the site that are only accessible when the user is logged in.