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
?