I saw a post that was dated 2021 where it was suggested to create a hook but i dont see it in the latest version. how do i send password change email automatically when i manually signup a user?
Hey there @Jaisantosh !
You can achieve this using a Post Registration Action and the /dbconnections/change_password endpoint of the Authentication API. An example Action might look like:
exports.onExecutePostUserRegistration = async (event, api) => {
const axios = require('axios');
const domain = '{your_domain}';
// Function to send password change email
const sendPasswordChangeEmail = async (email) => {
try {
await axios.post(`https://${domain}/dbconnections/change_password`, {
email: email,
connection: 'Username-Password-Authentication' //or whichever database connection you are using
}, {
headers: {
'Content-Type': 'application/json'
}
});
console.log('Password change email sent successfully.');
} catch (error) {
console.error('Error sending password change email:', error);
throw error;
}
};
// Execute the function
try {
await sendPasswordChangeEmail(event.user.email);
} catch (error) {
console.error('Error in post user registration action:', error);
}
}
This will immediately send the user an email to reset their password upon creation/registration.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.