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

> データベース接続のユーザーがパスワードをリセットまたは変更した後に実行される、Post Change Password フローと post-change-password Action トリガーについて説明します。このトリガーを使用すると、ユーザーのパスワードが変更されたことを別のシステムに通知できます。

# Post Change Password トリガー

Post Change Password トリガーは、ユーザーがパスワードをリセットまたは変更した後に実行されます。このトリガーを使用すると、パスワード変更後にユーザーへメールを送信したり、ユーザーのパスワードが変更されたことを別のシステムに通知したりできます。これにより、Auth0 で管理されていない他のセッションを無効化できます。

<Frame>
  <img src="https://mintcdn.com/translations/3nS3prIggmJG9TUI/docs/images/cdy7uua7fh8z/3i65TvmTpHkyDTqKvXAkMi/3adb8f0bd195cec4dd0a82cb87b270b9/post-change-password-flow.png?fit=max&auto=format&n=3nS3prIggmJG9TUI&q=85&s=78f68f243084bb68c75ed7ddc4821250" alt="Actions の Post Change Password フローを示す図" width="761" height="126" data-path="docs/images/cdy7uua7fh8z/3i65TvmTpHkyDTqKvXAkMi/3adb8f0bd195cec4dd0a82cb87b270b9/post-change-password-flow.png" />
</Frame>

このフローの Actions はノンブロッキング (非同期) です。つまり、Auth0 のパイプラインは Action の実行完了を待たずに処理を継続します。そのため、Action の実行結果は Auth0 のトランザクションに影響しません。

<div id="triggers">
  ## トリガー
</div>

<div id="post-change-password">
  ### Post Change Password
</div>

`post-change-password` トリガーは、データベース接続を使用するユーザーがパスワードをリセットまたは変更した後に実行されます。

このトリガーには複数の Actions を関連付けることができ、それらは順番に実行されます。ただし、これらの Actions は非同期で実行されるため、パスワードリセット処理を妨げることはありません。

<div id="reference">
  ### リファレンス
</div>

* [イベントオブジェクト](/ja/docs/customize/actions/explore-triggers/password-reset-triggers/post-change-password-trigger/post-change-password-event-object): パスワードが変更されたユーザーおよび接続に関するコンテキスト情報を提供します。
* [API オブジェクト](/ja/docs/customize/actions/explore-triggers/password-reset-triggers/post-change-password-trigger/post-change-password-api-object): フローの動作を変更するためのメソッドを提供します。

<div id="common-use-cases">
  ## 一般的な使用例
</div>

<div id="invalidate-the-users-session-in-another-system">
  ### 別のシステムでユーザーのセッションを無効化する
</div>

パスワード変更後の Action を使用すると、別のシステムでユーザーのセッションを無効化できます。

```javascript lines theme={null}
const axios = require("axios");

/**
 * @param {Event} event - パスワードが変更されたユーザーの詳細。
 */
exports.onExecutePostChangePassword = async (event) => {
  axios.post("https://my-api.exampleco.com/revoke-session", { params: { email: event.user.email }});
};
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  `axios` のような `npm` ライブラリを使用するには、そのライブラリを依存関係として Action に追加する必要があります。詳しくは、[Write Your First Action](/ja/docs/customize/actions/write-your-first-action) の「Add a dependency」セクションを参照してください。
</Callout>

<div id="send-an-email-after-the-user-changes-their-password">
  ### ユーザーがパスワードを変更した後、メールを送信する
</div>

```javascript lines expandable theme={null}
const axios = require("axios");

exports.onExecutePostChangePassword = async (event) => {
  try {
    // https://sendgrid.api-docs.io/v3.0/mail-send
    axios.post('https://api.sendgrid.com/v3/mail/send',
      {
        personalizations: [{
          to: [{ email: event.user.email }]
        }],
        from: { email: 'admin@exampleco.com' },
        subject: 'Your password was changed',
        content: [{
          type: 'text/plain',
          value: 'The password for your ' + event.connection.name + ' account ' + event.user.email + ' was recently changed.'
        }]
      },
      {
        headers: {
          'Authorization': 'Bearer ' + event.secrets.SENDGRID_API_KEY
        },
      }
    );
  } catch (err) {
    console.log(`Error sending email to ${event.user.email}:`, err.message)
  }
};
```
