Search code examples
luceneauth0auth0-delegated-admin

lucene query filter not working


I am using this filter hook in my Auth0 Delegated Administration Extension.

function(ctx, callback) {
  // Get the company from the current user's metadata.
  var company = ctx.request.user.app_metadata && ctx.request.user.app_metadata.company;
  if (!company || !company.length) {
    return callback(new Error('The current user is not part of any company.'));
  }

  // The GREEN company can see all users.
  if (company === 'GREEN') {
    return callback();
  }
  // Return the lucene query.
  return callback(null, 'app_metadata.company:"' + company + '"');
}

When user logged in whose company is GREEN can see all users. But when user logged in whose company is RED can't see any users whose company is RED.

I need to make this when user logged in, user should only be able to access users within his company. (except users from GREEN company).

But above code is not giving expected result. What could be the issue?


Solution

  • I finally ended up with this solution.

    Used search functionality to filter users. I had to change below two files.

    fetchUsers function in client\actions\user.js

    changed

    export function fetchUsers(search = '', reset = false, page = 0)

    to

    export function fetchUsers(search = '@red.com', reset = false, page = 0)

    AND

    onReset function in client\containers\Users\Users.jsx

    changed

    onReset = () => { this.props.fetchUsers('', true); }

    to

    onReset = () => { this.props.fetchUsers('@red.com', true); }