feat(#55): Enable sending account deletion emails through brevo npm package

This commit is contained in:
Josh Creek
2024-10-29 22:10:21 +00:00
parent c4865337ee
commit 464f365085
5 changed files with 357 additions and 13 deletions
+12 -12
View File
@@ -4,6 +4,7 @@ import type { Database, Tables, TablesInsert } from '$lib/types/supabase';
import { PUBLIC_SUPABASE_URL } from '$env/static/public';
import { SUPABASE_SERVICE_ROLE_KEY } from '$env/static/private';
import { stripe as stripeClient } from '$lib/utils/stripe';
import { sendEmail } from '../brevo/email';
const toDateTime = (secs: number) => {
const t = new Date(+0); // Unix epoch start.
@@ -494,18 +495,17 @@ const requestAccountDeletion = async (userId: string, userEmail: string, baseUrl
const deletionLink = `${baseUrl}/api/delete-account?token=${token}`;
// Send deletion email using Brevo
// try {
// await brevoClient.sendTransactionalEmail({
// to: [{ email: userEmail }],
// subject: 'Confirm Account Deletion',
// htmlContent: `<p>Click <a href="${deletionLink}">here</a> to confirm your account deletion.</p>`
// });
// console.log('Deletion email sent successfully.');
// } catch (emailError) {
// console.error('Failed to send deletion email:', emailError);
// throw new Error('Failed to send confirmation email.');
// }
console.log('Deletion email would be sent successfully.', deletionLink);
try {
await sendEmail(
'Confirm Account Deletion',
`<p>Click <a href="${deletionLink}">here</a> to confirm your account deletion.</p>`,
userEmail
);
console.log('Deletion email sent successfully.');
} catch (emailError) {
console.error('Failed to send deletion email:', emailError);
throw new Error('Failed to send confirmation email.');
}
};
const deleteAccount = async (token: string) => {