Files
myeasycms-v2/apps/dev-tool/app/emails/lib/email-loader.tsx
Giancarlo Buomprisco d31f3eb993 Add support for OTPs and enhance sensitive apis with OTP verification (#191)
One-Time Password (OTP) package added with comprehensive token management, including OTP verification for team account deletion and ownership transfer.
2025-03-01 17:35:09 +08:00

61 lines
1.4 KiB
TypeScript

import {
renderAccountDeleteEmail,
renderInviteEmail,
renderOtpEmail,
} from '@kit/email-templates';
export async function loadEmailTemplate(id: string) {
switch (id) {
case 'account-delete-email':
return renderAccountDeleteEmail({
productName: 'Makerkit',
userDisplayName: 'Giancarlo',
});
case 'invite-email':
return renderInviteEmail({
teamName: 'Makerkit',
teamLogo: '',
inviter: 'Giancarlo',
invitedUserEmail: 'test@makerkit.dev',
link: 'https://makerkit.dev',
productName: 'Makerkit',
});
case 'otp-email':
return renderOtpEmail({
productName: 'Makerkit',
otp: '123456',
});
case 'magic-link-email':
return loadFromFileSystem('magic-link');
case 'reset-password-email':
return loadFromFileSystem('reset-password');
case 'change-email-address-email':
return loadFromFileSystem('change-email-address');
case 'confirm-email':
return loadFromFileSystem('confirm-email');
default:
throw new Error(`Email template not found: ${id}`);
}
}
async function loadFromFileSystem(fileName: string) {
const { readFileSync } = await import('node:fs');
const { join } = await import('node:path');
const filePath = join(
process.cwd(),
`../web/supabase/templates/${fileName}.html`,
);
return {
html: readFileSync(filePath, 'utf8'),
};
}