# Delegated Adm: "User Details" view wrong memberships

**URL:** <https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329>\
**Category:** Get Help\
**Tags:** delegated-admin, bug\
**Created:** [March 23, 2018, 10:19am UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329 "2018-03-23T10:19:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sefa.ilkimen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sefa.ilkimen/32/4544_2.png) [@sefa.ilkimen](https://community.auth0.com/u/sefa.ilkimen)\
**Post date:** [March 23, 2018, 10:19am UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329/1 "2018-03-23T10:19:07Z")

</div>

I’ve setup Delegated Admin Extension to create new users and assign access rights to them. I’m providing an array (e.g. [‘User Management’, ‘Software Downloads’, ‘Support’]) in my Memberships Hook and it’s working just fine for the “Create User” view.  
But when I open the “User Details” view it’s always listing all access right, not the assigned ones. I think the problem is that the Hook is used for both scenarios: creating the list of available memberships and creating the list of assigned memberships.  
So basically, I need a possibility to tell if the Hook is requesting data for the “Create User” view or the “User Details” view. Is there any property available in the ctx object?

 ![User_Details](https://global.discourse-cdn.com/auth0/original/2X/d/d201e93fab5abe913e943a9917f694fa35697199.png)  
 ![Create_User](https://global.discourse-cdn.com/auth0/original/2X/f/f4c0739eec1785940b6b1841843d62f60e9f746e.png)

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [April 3, 2018, 1:36pm UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329/3 "2018-04-03T13:36:48Z")

</div>

I believe you can leverage the fact that when called at initialization to get a list of memberships that the currently logged in user to the extension can select when creating users the `ctx.payload.role` property will be set. This seems to indicate if the current user is a DAE admin or just a regular user, but could work to disambiguate from a view user call (unless the end-users themselves also have a root `role` property which I didn’t test).

A quick test shows that something like the following could be used to differentiate the calls:

```auto
function(ctx, callback) {
 
  if(ctx.payload.user.role) {
    ctx.log("Initialization request associated with DAE user itself.");
    
    var department = ctx.payload.user.app_metadata.department;
    
    if (department === 'IT') {
       return callback(null, ['IT', 'HR', 'Finance', 'Marketing', "TSE"]);
    }
    
    return callback(null, [department]);
  }
  
  ctx.log("View end-user details request.");
  
  return callback(null, ctx.payload.user.app_metadata.memberships);
}

```

When there’s a role I assume it’s a call to get the drop down values (you can tweak this condition further). I also then check another property, in my case, a department to see if the DAE user can create users in multiple memberships or just one. If it’s not the initialization call I just return the data from `ctx.payload.user.app_metadata.memberships` which is where selected memberships will be stored by default.

---

<div class="post-metadata">

**Author:** ![sefa.ilkimen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sefa.ilkimen/32/4544_2.png) [@sefa.ilkimen](https://community.auth0.com/u/sefa.ilkimen)\
**Post date:** [April 3, 2018, 3:05pm UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329/4 "2018-04-03T15:05:57Z")

</div>

Hi João,

thanks for your response! I was able to fix this on myself already, but I couldn’t find a way to reply on my own post or editing it. This is what I came up with:

```
// requesting assigned memberships
if (ctx.request.user.email !== ctx.payload.user.email) {
   return callback(null, othersAccessRights);
}

// requesting list of assignable memberships (alias my own memberships)
return callback(null, assignableAccessRights);

```

But I have another problem which is very urgent. Can you please have a look into that issue [Need to query app\_metadata in Delegated Admin Extension](http://community.auth0.com/t/need-to-query-app-metadata-in-delegated-admin-extension/10260)?

Thank you in anticipation!

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [April 3, 2018, 3:20pm UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329/5 "2018-04-03T15:20:22Z")

</div>

I left a reply there, but it’s not the best news I’m afraid…

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 25, 2019, 12:38pm UTC](https://community.auth0.com/t/delegated-adm-user-details-view-wrong-memberships/10329/6 "2019-07-25T12:38:05Z")

</div>


