嗨,我正在尝试做与此问题相同的事情: 如何在 Auth0 中为新用户发送密码更改电子邮件而不是验证电子邮件
我基本上正在尝试做同样的事情,但是将代码放入 auth0 操作中,而不是像以前那样放入规则和挂钩中。
我尝试查看 auth0 文档和论坛,但没有找到答案。 这是我在 auth0 论坛上找到的最接近的答案:https://community.auth0.com/t/auth0-password-change-with-actions/119868
您可以使用 Auth0 操作来执行此操作。请按照以下步骤操作
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访问更改密码电子邮件并在用户注册后执行该过程
Actions -> Flows -> Post User Registration -> Go to the custom tab and drag and drop your action card between start and complete
。尝试一下并让我知道结果