Improve this doc View source

SpStateConfig
object in module stormpath

Description

The Stormpath State Config is an object that you can define on a UI Router state. Use this configuration to define access control for your routes, as defined by UI Router.

You will need to be using the UI Router module, and you need to enable the integration by calling $stormpath.uiRouter() in your application's config block.

If you're using Angular's built-in $routeProvider instead of UI Router, please use $stormpath.ngRouter() instead.

NOTE: Do not define this configuration on a abstract state, it must go on the child state. However, the controller of the abstract state will be initialized AFTER any configuration rules of the child state have been met.

Support for data.authorities

If you have used JHipster to generate your project, you are likely using the data.authorities property to define authorization for your views. This library will look for the data.authorities property and apply the same logic as our own sp.authorize property.

Properties

Example


angular.module('myApp')
  .config(function ($stateProvider) {

    // Wait until we know if the user is logged in before showing the homepage
    $stateProvider
      .state('main', {
        url: '/',
        sp: {
          waitForUser: true
        }
      });

    // Require a user to be authenticated in order to see this state
    $stateProvider
      .state('secrets', {
        url: '/secrets',
        controller: 'SecretsCtrl',
        sp: {
          authenticate: true
        }
      });

    // Require a user to be in the admins group in order to see this state
    $stateProvider
      .state('secrets', {
        url: '/admin',
        controller: 'AdminCtrl',
        sp: {
          authorize: {
            group: 'admins'
          }
        }
      });
});

If using JHipster generated code:

    // Require a user to be in the admins group in order to see this state
    $stateProvider
      .state('secrets', {
        url: '/admin',
        controller: 'AdminCtrl',
        data: {
          authorities: ['admins']
        }
      });