RafaelVidaurre / angular-permission

Simple route authorization via roles/permissions
MIT License
1.13k stars 212 forks source link

State params not passed to signin state #451

Open dragos-cojocari opened 5 years ago

dragos-cojocari commented 5 years ago

Environment:

Behavior:

Issue: Is state params transfer supported? Do I have a configuration error?

main.module.js

function routeConfig($stateProvider) {
  $stateProvider
    .state('main', {
      url: '/:tenantid/',
      replace: "false",
      templateUrl: 'pages/main.html',
      redirectTo: 'main.dashboard',
      data: {
        access: ['AUTHORIZED', 'ADMIN'],
        permissions: {
          only: ['AUTHORIZED'],
          redirectTo: function(rejectedPermission, transitionProperties) {
            return {
              state: 'signin',
              options: {
                reload: true
              }
            };
          }
        }
      }
    });

login.module.js

function routeConfig($stateProvider) {
  $stateProvider
    .state('signin', {
      url: '/signin/:tenantid',
      templateUrl: 'pages/login/signin.html'
    });
}

The transitionProperties shows the following:


{
  "toState": {
    "url": "/signin/:tenantid",
    "templateUrl": "pages/login/signin.html",
    "name": "signin",
    "$$isAuthorizationFinished": false
  },
  "toParams": {
    "tenantid": ""
  },
  "fromState": {
    "name": "",
    "url": "^",
    "views": null,
    "abstract": true
  },
  "fromParams": {},
  "options": {
    "location": true,
    "inherit": true,
    "relative": {
      "self": {
        "name": "",
        "url": "^",
        "views": null,
        "abstract": true
      },
      "resolve": {},
      "url": {
        "segments": [
          ""
        ],
        "params": {},
        "source": "",
        "sourcePath": "",
        "sourceSearch": "",
        "regexp": {},
        "prefix": "",
        "$$paramNames": []
      },
      "navigable": null,
      "ownParams": {},
      "params": {},
      "views": {},
      "path": [],
      "includes": {
        "": true
      },
      "locals": {
        "resolve": null,
        "globals": {
          "$stateParams": {}
        }
      }
    },
    "notify": true,
    "reload": true,
    "$retry": false
  }
}```

Thank you.
masterspambot commented 5 years ago

I think that solution to your problem is explained here: https://github.com/RafaelVidaurre/angular-permission/wiki/Usage-in-ui-router-states#single-redirection-rule https://github.com/RafaelVidaurre/angular-permission/wiki/Usage-in-ui-router-states#dynamic-redirection-rules

See that params has to be passed to redirection function in order to be handled properly by router.

dragos-cojocari commented 5 years ago

Thanks @masterspambot masterspambot

See that params has to be passed to redirection function in order to be handled properly by router. Right, I saw that but my problem is that no params or state params or transitionProperties are available in the redirectTo function. The param is not static, it comes from the stateParams of the previous state.