AngularJS - Redirect to Login page and Persistence of Session ID

后端 未结 4 1211
一向
一向 2021-01-30 14:57

I am looking for a way to do these two things, first I want to redirect the user to a login page if no SessionID is found and second I would like to hear your opinion about pers

4条回答
  •  醉梦人生
    2021-01-30 15:44

    this will work. It works fine in my application

    var interceptor = function ($q, $location) {
            return {
                request: function (config) {//req
                    console.log(config);
                    return config;
                },
    
                response: function (result) {//res
                    console.log('Repos:');
                    console.log(result.status);
                    return result;
                },
    
                responseError: function (rejection) {//error
                    console.log('Failed with', rejection.status, 'status');
                    if (rejection.status == 403) {
                        $location.url('/dashboard');
                    }
    
                    return $q.reject(rejection);
                }
            }
        };
        module.config(function ($httpProvider) {
            $httpProvider.interceptors.push(interceptor);
        });
    

提交回复
热议问题