Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirection after login

I have a redirection problem in my app. These are my state providers:

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

$stateProvider

.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})

.state('app2', {
url: "/app2",
abstract: true,
templateUrl: "templates/menu2.html",
controller: 'AppCtrl'
})

.state('app2.login', {
url: "/login",
views: {
  'menuContent': {
    templateUrl: "templates/login.html",
    controller: 'LoginCtrl'
  }
}
})

.state('app.profile', {
url: "/profile",
views: {
  'profile' :{
      templateUrl: "templates/profile.html",
      controller: "ProfileCtrl"
  }
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app2/login');
});

My AppCtrl is empty and this is my LoginCtrl:

testApplication.controller('LoginCtrl', function($scope, $location){ 
 $scope.fbLogin = function() { 
   openFB.login( function(response) { 
     if (response.status === 'connected') {
       // This runs on success 
        console.log('Facebook login succeeded');
        $scope.$apply( function () { $location.path('profile') } ); 
     } else { 
          alert('Facebook login failed'); 
     } 
   }, {scope: 'email,publish_actions,user_friends'}
  ); 
 }; 
})

The problem is that I don't get redirected after login. But if I change

$urlRouterProvider.otherwise('/app2/login');

to

$urlRouterProvider.otherwise('/app/profile');

And go manually to "#/app2/login" to login I get redirected to the profile page. How can I fix that?

like image 532
nikitz Avatar asked Apr 25 '26 23:04

nikitz


1 Answers

Try

$state.go('app.profile') 

instead of

$scope.$apply( function () { $location.path('profile') } );

I hope this helps others too.

like image 74
Taku Avatar answered Apr 28 '26 11:04

Taku