SpStateConfig
stormpath
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.
data.authoritiesIf 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.
If true, the user must be authenticated in order to view this state.
If the user is not authenticated, they will
be redirected to the login state. After they login, they will be redirected to
the state that was originally requested.
If true, delay the state transition until we know
if the user is authenticated or not. This is useful for situations where
you want everyone to see this state, but the state may look different
depending on the user's authentication state.
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']
}
});