2024 年如何为 Auth0 中的新用户发送密码更改电子邮件而不是验证电子邮件

问题描述 投票:0回答:1

嗨,我正在尝试做与此问题相同的事情: 如何在 Auth0 中为新用户发送密码更改电子邮件而不是验证电子邮件

我基本上正在尝试做同样的事情,但是将代码放入 auth0 操作中,而不是像以前那样放入规则和挂钩中。

我尝试查看 auth0 文档和论坛,但没有找到答案。 这是我在 auth0 论坛上找到的最接近的答案:https://community.auth0.com/t/auth0-password-change-with-actions/119868

node.js auth0
1个回答
0
投票

您可以使用 Auth0 操作来执行此操作。请按照以下步骤操作

  1. 前往
    Actions -> Library -> Click Create Action -> Select Build From Scratch -> Then add this to the script
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
* @param {PostUserRegistrationAPI} api - Methods and utilities to help change the behavior after a signup.
*/

var axios = require("axios").default;

exports.onExecutePostUserRegistration = async (event, api) => {

    var data = {
      'client_id': event.client_id,
      'email': event.user.email,
      'connection': event.connection.name
    }

    const headers = {
      'Content-Type': 'application/json'
    }

    await axios.post("https://<Auth0_Tenant_Domain>.auth0.com/dbconnections/change_password", data, {
        headers: headers
    });

};

确保在依赖项中添加 axios

我们在这里所做的是通过身份验证管理API访问更改密码电子邮件并在用户注册后执行该过程

  1. 现在保存并部署更改。
  2. 现在前往
    Actions -> Flows -> Post User Registration -> Go to the custom tab and drag and drop your action card between start and complete

  1. 现在单击“应用”按钮。

尝试一下并让我知道结果

© www.soinside.com 2019 - 2024. All rights reserved.