RafaelVidaurre / angular-permission

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

Set up roles and permissions after authentication #429

Closed HarshaSuranjith closed 7 years ago

HarshaSuranjith commented 7 years ago

Hi, @Narzerus
I have an angular application running with a Java back-end. After authentication the server returns a authentication object with assigned roles to the user. But I`m not clear how to inject them to the PermPermissionStore when the login is successful. Can you guys give me some pointers or direct me to an example where such case is implemented.

Thanks

joariasl commented 7 years ago

Try with:

angular
  .module('yourApp')
  .config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.deferIntercept();
    ...
  })
  .run(function($rootScope, Auth, PermPermissionStore, $urlRouter){
    Auth.getPermissions().then(function(result){
      PermPermissionStore.defineManyPermissions(result.data, function (permissionName) {
        return true;
      });
      $urlRouter.sync();
      $urlRouter.listen();
    });
  });
iMomen commented 6 years ago

@joariasl I think this is useful when the user is already signed in but I think @HarshaSuranjith is asking about how to change this after user login and you have already initiated the permission in app.run