title: How to handle authentication in Angular JS application
body: <p>I am implementing an auth system in my angular js app.</p>
  
  <p>What I am planning it like below:</p>
  
  <ol>
  <li>Get user info(name and pass from login form) </li>
  <li>Check whether user exists or not</li>
  <li>if exists server respond with a session cookie and frontend will redirect to a certain page.</li>
  <li>then user will do some task which will generate API request</li>
  <li>API request should have cookie information that was sent on step 3</li>
  <li>server check whether the cookie was generated or not and if cookie was found then respond with the API request results. And in my service I am doing something like   </li>
  </ol>
  
  <pre>
      MyApp.service('myAuth', function($http, $q) {
          this.authHeader = null;
          this.checkAuth = function(){
          //do api call and if success sets this.authHeader = response
          }
          this.isAuthenticaed = function(){
              this.authHeader ? return this.authHeder  : return false;
         }
  </pre>
  
  <p>After submitting the login form I will call checkAuth and get my session cookie back from my server, how I can add the cookie information while doing the next REST call and also when user will navigate throughout the application after log in I do want to check each time isAuthenticaed true or false, in Angularjs when it will navigate to another page does it resets after setting it true from the first call? And is my approach 1-6 good or do you have any specific suggestions?
  Btw I checked previous so entries but those are not what I want to know.</p>