> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 委任管理：メンバーシップクエリフック

> 委任管理拡張機能にメンバーシップクエリフックを使用する方法について説明します。

新しいユーザーの作成では、ユーザーインターフェイスにドロップダウンが表示され、ユーザーに割り当てるメンバーシップを選択することができます。これらのメンバーシップは **メンバーシップクエリフック** を使って定義されます。

<div id="hook-contract">
  ## フックコントラクト
</div>

* **ctx** ：コンテキストオブジェクトです。
* **`callback(error, { createMemberships: true/false, memberships:})`** ：エラーとメンバーシップ構成を含むオブジェクトを返すコールバックです。

<div id="sample-use">
  ## 使用例
</div>

IT部のユーザーは他の部署にユーザーを作成できなくてはなりません。他の部署のユーザーは自身の部署にのみユーザーを作成できなくてはなりません。

```javascript lines theme={null}
function(ctx, callback) {
  var currentDepartment = ctx.payload.user.app_metadata && ctx.payload.user.app_metadata.department;
  if (!currentDepartment || !currentDepartment.length) {
    return callback(null, [ ]);
  }

  if (currentDepartment === 'IT') {
    return callback(null, [ 'IT', 'HR', 'Finance', 'Marketing' ]);
  }

  return callback(null, [ ctx.payload.user.app_metadata.department ]);
}
```

<div id="notes">
  ## 注記
</div>

このクエリが使用できるのはUI内だけであるため、特定部署のユーザー割り当てにルールの実行が必要な場合には、 **書き込みフック** を使用してメンバーシップを割り当てなければなりません。

メンバーシップのグループが1つだけの場合、UIに［Memberships（メンバーシップ）］フィールドは表示されません。

**createMemberships** をtrueに設定すると、エンドユーザーが **memberships** フィールドに任意の値を入力できるようになります。

```javascript lines theme={null}
function(ctx, callback) {
  var currentDepartment = ctx.payload.user.app_metadata.department;
  if (!currentDepartment || !currentDepartment.length) {
    return callback(null, [ ]);
  }

  return callback(null, {
    createMemberships: ctx.payload.user.app_metadata.department === 'IT' ? true : false,
    memberships: [ ctx.payload.user.app_metadata.department ]
  });
}
```

<div id="learn-more">
  ## もっと詳しく
</div>

* [委任管理：アクセスフック](/docs/ja-JP/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-access-hook)
* [委任管理：フィルターフック](/docs/ja-JP/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-filter-hook)
* [委任管理：クエリ設定フック](/docs/ja-JP/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-settings-query-hook)
* [委任管理：書き込みフック](/docs/ja-JP/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-write-hook)
