0

我想在我的系统中增加限制。然后我使用了 JWT 令牌。然后我更喜欢前端的 statellizer。

一旦用户登录系统。它将生成这样的令牌

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRlc3RAZ21haWwuY29tIiwiaWF0IjoxNDU1NzAzAzNTE5fQ.I6z8jlXx4H1R3gNOAnOysdI0qyeU01GAlnYWeQZKThs

但是情况是当用户成功登录系统时。它将重定向到仪表板但令牌没有与请求绑定。

其他请求仅在仪表板中正常工作。

控制器中的登录功能

         $scope.authLogin = function () {
           $auth.login({
             email: $scope.email, password: $scope.password
           }).then(function(res){
             //userService.setUser(res.data.user);
             toastr.success('Successfully login ', 'Message', {
               closeButton: true
             });
             window.location = '/dashboard';
           }).catch(function onError() {
               toastr.error('Invalid email/password combination.', 'Error', {
                 closeButton: true
               });
           });
         };

路线文件

'/login'  : { view: 'static/login'},
'/signup' : { view : 'static/signup'},
'/'       : { view: 'static/login' },
'GET /dashboard' : 'PageController.showDashboard', 

政策文件

  'UserController':{
    '*':['jwtAuth'],
    authLog : true
   // signUp : true
  },

  'PageController': {
    '*': ['jwtAuth']
  }

我想让它就像任何人都无法在没有令牌的情况下访问仪表板一样。我希望我的问题很清楚。

谢谢

4

1 回答 1

0

我尝试过的方式,这是错误的,因为当我们调用GET /dashboard函数时,无法将令牌与请求绑定。此方法与会话完美配合。

我使用了以下方法。它对我有用。这更方便用帆处理 JWT。

带有帆的 json-web-tokens-examples

于 2016-02-23T09:55:21.647 回答