title: How to store user session in AngularJS?
body: <p>I have just started using AngularJS and I'm trying to store user session on my AngularApp.</p>
  
  <p>First step to submit username and password works. 
  After that, I store the <code>username</code> retrieved from the service in the <code>$rootScope</code>.
  The next page can display the <code>username</code> stored. </p>
  
  <p>But after a refresh, the <code>$rootScope</code> is empty.</p>
  
  <p>I'm trying to do an authentication system as simple as possible. </p>
  
  <pre><code>myApp.controller('loginController', ['$scope', '$rootScope', '$location', 'AuthService', '$route',
    function ($scope, $rootScope, $location, AuthService, $route) {
  
        $scope.login = function (credentials) {
          AuthService.login(credentials).then(function (response) {
            if(response.data == "0"){
              alert("Identifiant ou mot de passe incorrect");
            }
            else {
              // response.data is the JSON below 
              $rootScope.credentials = response.data;           
              $location.path("/");
            }
          });
        };
  
  }]);
  </code></pre>
  
  <p><code>AuthService.login()</code> makes a <code>$http</code> request.</p>
  
  <p>JSON </p>
  
  <pre><code> {user_id: 1, user_name: "u1", user_display_name: "Steffi"} 
  </code></pre>
  
  <p>HTML : </p>
  
  <pre><code> &lt;div&gt;Welcome {{ credentials.user_display_name }}!&lt;/div&gt;
  </code></pre>
  
  <p>I tried a lot of tutorials, but I can't make session work. 
  I already used UserApp but it's not ok to me. I would like to create my own <strong>simple</strong> authentication.</p>