How to redirect to tabs after login completion


#1

Here is my app.js file content:

.config(function($stateProvider, $urlRouterProvider) {
// alert(“In Config”)
$stateProvider
.state(‘login’, {
url: ‘/login’,
templateUrl: ‘templates/login.html’,
controller: ‘LoginController’
})
.state(‘tab’, {
cache: true,
url: ‘/tab’,
abstract: true,
templateUrl: ‘templates/tab.html’
})

.state(‘tab.dash’, {
url: ‘/dash’,
views: {
‘tab-dash’: {
templateUrl: ‘templates/tab-dash.html’,
controller: ‘DashCtrl’
}
}
})

And loginControler looks like this

.controller(‘LoginController’, function($scope, $http, $location, $q, $state) {
alert(“In LoginController “)
var validate = false;
$http.defaults.headers.post[‘Content-Type’] = ‘application/x-www-form-urlencoded’;
$scope.login = function() {
var deferred = $q.defer();
var redirect_url = “newapp://tab”;
var ref=window.open(’****?client_id=’ + clientId + ‘&redirect_uri=newapp://tab&scope=cecauth&approval_prompt=force&response_type=token’, ‘_blank’, ‘location=no’);
alert(“Ionic Login 2”)
ref.addEventListener(‘loadstart’, function(event) {
var event_url = event.url
if((event.url).startsWith(“http://”)) {
event_url = event_url.substring(7,event_url.length)
alert(event_url )
event.url = event_url
}
var isRedirectURL=(event_url).startsWith(redirect_url);
if(isRedirectURL) {
validate=true;
ref.removeEventListener(“exit”,function(event){});
//requestToken = (event.url).split(“code=”)[1];
alert(“Ionic Login 5”)
var callbackResponse = (event_url).split(”#”)[1];
var responseParameters = (callbackResponse).split("&");
alert("responseParameters " + responseParameters + "callbackResponse " + callbackResponse )
event.url = “/tab”
$location.path(“tab”);
ref.close();
$state.go(‘tab’);
//$state.go(‘main.dash’, {}, {reload: true});
//$scope.setCurrentUsername(data.username);
//$state.go(‘tab.home’,{},{location:‘replace’});
}
});
}

After Login completion. It is redirected to tsb.chat tab. But if I click on any other tabs like dash. It is again going back to login page. Can someone suggest me what am I missing here?

Thanks