【问题标题】:Handle JWT token with private pages in sails js在sails js中处理带有私有页面的JWT令牌
【发布时间】:2016-05-28 23:07:50
【问题描述】:

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

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

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRlc3RAZ21haWwuY29tIiwiaWF0IjoxNDU1NzAzNTE5fQ.I6z8jlXx4H1R3gNOAnOysdI0qyeU01GAlnYWeQZKThs

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

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

Controller中的登录功能

         $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']
  }

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

谢谢

【问题讨论】:

    标签: angularjs node.js sails.js jwt satellizer


    【解决方案1】:

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

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

    json-web-tokens-examples with sails

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 2022-01-03
      • 2016-01-10
      • 2012-05-14
      • 2017-07-04
      • 2017-06-10
      • 2017-01-14
      • 2016-03-06
      • 2022-11-15
      相关资源
      最近更新 更多