Show login page when session expired

Posted by Dennis on 07-Dec-2017 06:44

How can I automaticly show the login page when the session expires? 

Actually the user gets a general error and has to refresh the page.

Posted by Radoslav Kirilov on 08-Dec-2017 03:34

Hi

Into the current version of the application we do not have such functionality implemented built-in. I will put this requirement in our back log and we will prioritize it for the next major version of the product. At meantime, you can try using following code as workaround:

app/script/extensions/index.js

// Import your custom modules here:

export default angular.module('app.extensions.module', [

    // Put your custom modules here:

]).run(['$rootScope', 'providerService', '$state', function($rootScope, providerService, $state) {

    var lastDigestRun = new Date();

    $rootScope.$watch(function detectIdle() {

      var now = new Date();

      if (now - lastDigestRun > 20*1000*60) {

        providerService.unRegisterProviders()

            .then(function() {

                $rootScope.hasAuthProviders = false;

                $state.go('login');

            })

            .catch(function() {

                //Error handling

                $state.go('default.module.application.home');

            });

      }

      lastDigestRun = now;

    })}])

.name;

 

Best,

Rado

All Replies

Posted by Radoslav Kirilov on 08-Dec-2017 03:34

Hi

Into the current version of the application we do not have such functionality implemented built-in. I will put this requirement in our back log and we will prioritize it for the next major version of the product. At meantime, you can try using following code as workaround:

app/script/extensions/index.js

// Import your custom modules here:

export default angular.module('app.extensions.module', [

    // Put your custom modules here:

]).run(['$rootScope', 'providerService', '$state', function($rootScope, providerService, $state) {

    var lastDigestRun = new Date();

    $rootScope.$watch(function detectIdle() {

      var now = new Date();

      if (now - lastDigestRun > 20*1000*60) {

        providerService.unRegisterProviders()

            .then(function() {

                $rootScope.hasAuthProviders = false;

                $state.go('login');

            })

            .catch(function() {

                //Error handling

                $state.go('default.module.application.home');

            });

      }

      lastDigestRun = now;

    })}])

.name;

 

Best,

Rado

Posted by Dennis on 16-Dec-2017 07:43

This is absolutly answering the Question. But the problem is, my question was wrong. I have to go to the login page everytime the server is responsing an error 401.

For Invoke operations I know I can search for the return value 401. But then I have to implent it in every request and what is with the filter or the page function from the grid and so on.

Can I also impelment a $watch for every request on the server to check the answer for a returning 401?

Posted by Radoslav Kirilov on 18-Dec-2017 02:46

Hi


You could specify a default error handler for the dataSource:

kendo.data.DataSource.prototype.options.error = function (e) {
    if (e.status === 401) {
        //your logic
    }
};


This can be put in an extension file of the custom module.


Best,
Rado

This thread is closed