question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async permissions definition

See original GitHub issue

Hi,

I have a little problem: I have to update permissions after call an async request to the server, how should I do?

I have this permissions definition:

    // GUEST
    PermissionStore
      .definePermission(USER_ROLES.guest, guest);

      function guest(){
        if ($rootScope.auth === USER_ROLES.guest || !$rootScope.auth) {
          return true;
        }
        return false;
      }

    // USER
    PermissionStore
      .definePermission(USER_ROLES.user, user);

      function user(){
        if ($rootScope.auth === USER_ROLES.user) {
          return true;
        }
        return false;
      }

    // ADMIN
    PermissionStore
      .definePermission(USER_ROLES.admin, admin);

      function admin(){
        if ($rootScope.auth === USER_ROLES.admin) {
          return true;
        }
        return false;
      }

and this is my async factory call to retrieve logged user data (and permission too)


      deferred = $q.defer();

      var apiUrl = 'http://localhost:8080/authorizer';

      $http.post(apiUrl, null, {withCredentials: true})
      .then(userLoginSuccess)
      .catch(userLoginError);

      return deferred.promise;

    // success
    function userLoginSuccess(response){
      deferred.resolve(response);
    }

    // error
    function userLoginError(err){
      deferred.reject(err);
    }

How can I update permissions? Your documentation isn’t very clear

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
masterspambotcommented, Mar 11, 2016

Change success callback and redefine permissions there:

 // success
    function userLoginSuccess(response){
      // PermissionStore.defineManyPermissions(...) 
      deferred.resolve(response);
    }
0reactions
ibbattacommented, Mar 11, 2016

@masterspambot thanks a lot 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ...
Read more >
How to change the permissions of a file asynchronously using ...
To change permission on a file asynchronously, you can use the chmod() function from the fs (filesystem) module in Node.js.
Read more >
Unblocking clipboard access - web.dev
The Async Clipboard API addresses these issues, providing a well-defined permissions model that doesn't block the page. The Async Clipboard ...
Read more >
Asynchronous file access (C#) - Microsoft Learn
Learn how to use the async feature to access files in C#. You can call into asynchronous methods without using callbacks or splitting...
Read more >
How to do asynchronous task while defining a permission ...
I'm using angular-permission library along with ui-router and satellizer. Following is the state definition for home . In that I'm checking ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found