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

# パスワード変更後フロー

> データベース接続ユーザーがパスワードをリセット・変更したときに実行される、パスワード変更後フローとpost-change-passworアクショントリガーについてご説明します。このトリガーを使って、ユーザーのパスワードの変更を他のシステムに通知することもできます。

パスワード変更後フローは、ユーザーがパスワードをリセット・変更した後に実行されます。このフローを使ってパスワード変更後にユーザーにメールを送ったり、他のシステムに変更を通知したりすれば、Auth0で管理されていないセッションを取り消すことができます。

<Frame>
  <img src="https://mintcdn.com/docs-dev-fix-docs-5525/DnsGtoeaK8u0_zJV/docs/images/ja-jp/cdy7uua7fh8z/3i65TvmTpHkyDTqKvXAkMi/14529986b16e71f83df8f85c16776fe1/post-change-password-flow.png?fit=max&auto=format&n=DnsGtoeaK8u0_zJV&q=85&s=54ac3cc28ba805ac773ca44fbf3b5f51" alt="アクションのパスワード変更後フローを示す図。" width="761" height="126" data-path="docs/images/ja-jp/cdy7uua7fh8z/3i65TvmTpHkyDTqKvXAkMi/14529986b16e71f83df8f85c16776fe1/post-change-password-flow.png" />
</Frame>

このフローのアクションは非ブロック（非同期）であるため、Authパイプラインの実行はアクションの完了を待たずに継続されます。そのため、アクションの結果は、Auth0のトランザクションに影響しません。

## トリガー

### パスワード変更後

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

このトリガーには、複数のアクションを結びつけることができ、アクションは順番に実行されます。ただし、これらのアクションは非同期で実行されるため、パスワードリセットのプロセスがブロックされることはありません。

### リファレンス

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

## 一般的なユースケース

### ユーザーの他のシステムでのセッションを無効にする

post-change-passwordアクションを使うと、そのユーザーの他のシステムでのセッションを無効にすることができます。

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

/**
 * @param {Event} event - Details about user whose password was changed.
 */
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`ライブラリーを使用する場合は、そのライブラリーをアクションに依存関係として追加しなければなりません。詳細については、「[初めてアクションを作成する](/docs/ja-jp/customize/actions/write-your-first-action)」の「依存関係を追加する」セクションをお読みください。
</Callout>

### ユーザーのパスワード変更後にメールを送信する

```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)
  }
};
```
