this is what my lifecycles.ts look look like:
import axios from "axios";
let previousVerificationStatus: string | null = null;
export default {
async beforeUpdate(event: { params: { where: { id: number } } }) {
const { where } = event.params;
const entity = await strapi.entityService.findOne(
"api::kinde-user.kinde-user",
where.id,
{
fields: ["verification_status"],
}
);
previousVerificationStatus = entity.verification_status;
},
async afterUpdate(event: {
params: {
data: { verification_status: string; firstName: string; email: string };
};
}) {
const { data } = event.params;
if (
data.verification_status === "verified" &&
previousVerificationStatus !== "verified"
) {
console.log("User has been verified");
console.log("------------");
console.log("------------", data.email);
const emailData = {
subject: "Your account has been verified",
html_content: `<p>Welcome, ${data.firstName}! Your account has been <strong>verified</strong>! You can now start adding listings. 🙂</p>`,
to: [data.email],
};
try {
const response = await axios.post(
"http://127.0.0.1:8000/api/emails/send/",
emailData,
{
headers: {
"Content-Type": "application/json",
},
}
);
console.log(
"Verification email sent successfully. Server said:",
response.data.message
);
} catch (error) {
console.error(
"Failed to send verification email:",
JSON.stringify(error.response.data, null, 2)
);
}
}
previousVerificationStatus = null;
},
};