1

In my application, i use authorization headers, and after some user action (login), i want to set for each request additional header.

 var app = angular.module('app', ['ui.router']);

 app.config(function($stateProvider, $urlRouterProvider) {

     $urlRouterProvider.otherwise("/");

     $stateProvider.state("login", { 
       url: "login",
       templateUrl: "common/login"   
     })
     .state("secured", {
       url: "secured",
       templateUrl: "secured/secured"
     });

 });

When user enter you name and password, in backend of my application i set X-Auth-Header and return it.

//frontend controller for login form

userControllers.controller('userController', ['$scope', '$http', '$state', 
   function($scope, $http, $state) {
      //on button click i send information about user 
      $scope.send = function(user) {

         $http.post('api/login', user).
            success(function() {
               //all ok, i should change state to secured
               $state.go("secured");
            }).
            error(function() {
                //handler errors
            }); 
      }  

}]);

When after success user input i change $state, i want send X-Auth-Header with change state, is it possible with ui router?

And how to restrict secured area, if user browser change url on /#/secured?

mike
  • 749
  • 10
  • 21
  • Hi mike, have a look at this link; it might be interesting for you: http://stackoverflow.com/questions/22537311/angular-ui-router-login-authentication – timtos Nov 07 '14 at 13:14
  • If you solved this, can you please share how you made it? Thanks. – P.M Mar 03 '15 at 00:47

1 Answers1

0

I don't know if you still have the same problem, but the guy at http://onehungrymind.com/winning-http-interceptors-angularjs/ solved most of my problems: router-ui doesn't remove option to use classic angularjs' $http interceptors! I hope this works

P.M
  • 2,880
  • 3
  • 43
  • 53