0

I have AngularJS website which contains few hyperlink. Whenever I try to open the link in same tab then it is working fine but whenever I try to open the link in new tab then it is redirecting me to login page.

RouteController.js

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

app.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/login');
    $stateProvider
        .state('introduction', {
            url: '/',
            views: {
                'mainview':
                {
                    templateUrl: 'HomeLoginPages/Login.html',
                    controller: 'ctrlLogin'
                }
            }
        })
        .state('login', {
            url: '/login',
            views: {
                'mainview':
                {
                    templateUrl: 'HomeLoginPages/Login.html',
                    controller: 'ctrlLogin'
                }
            }
        })
        .state('home.eventlist.requestdetail', {
            url: '/requestdetail',
            params: { paramOne: "defaultValueOne", paramTwo: "defaultValueTwo", paramThree: "defaultValueThree", paramFour: "defaultValueFour" },
            views: {
                'homedetailview@home':
                {
                    templateUrl: 'RequestPages/DetailedRequest.html',
                    controller: 'ctrlRequestDetail',

                }
            }
        })
})

HTML File

<form class="form-main">
    <div class="div-main">
        <div class="gridBigStyle" ui-grid="gridEventList" ui-grid-pagination>
        </div>
    </div>
</form>

Controller.js

var myApp = angular.module('appHome');
myApp.controller("ctrlEventList", ['$scope', 'MetadataOrgFactory', function ($scope, MetadataOrgFactory) {
    $scope.gridEventList = {
        data: 'eventlistdata',     
        columnDefs: [
            { field: 'SiteEventNumber', displayName: 'Event Number' },
            {
                field: 'RequestNumber', displayName: 'Event Request',
                cellTemplate: '<a ui-sref=".requestdetail({paramOne:row.entity.RequestId, paramTwo:row.entity.EventId, paramThree: 1,paramFour: defaultValueFour})" class="ui-grid-cell-contents">{{COL_FIELD}}</a>'
            },
        ]
    }
}]);

I am using Token Authentication during login of user. The token is valid always but it is still redirecting me to Login Page.

simple user
  • 349
  • 3
  • 22
  • 44
  • Where do you store the token? Is it shared across tabs? – Protozoid May 31 '18 at 16:07
  • The token is stored in Sessionstorage. How to share this across the tab and how this token can be used to authorize WEB API Service call in new tab? – simple user May 31 '18 at 19:14
  • Please try this. Open dev tools and look at the sessionStorage item (in Chrome it's under dev tools -> Application -> Cookies), open another tab with dev tools and then load your page by pasting a URL, do you see the sessionStorage being carried across? – Protozoid Jun 01 '18 at 08:52

1 Answers1

0

I have saved the login information in localstorage variable which is used in all tabs. When user log out then I have explicitly set the value to blank so that all other tabs page will be redirect to login page. I hope this answer will help others.

simple user
  • 349
  • 3
  • 22
  • 44