backend project

This commit is contained in:
Sone
2025-11-02 10:05:02 +01:00
parent e4199f65d8
commit deb622b796
62 changed files with 12475 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import nodemailer from "nodemailer";
const smtpHost = process.env.SMTP_HOST || "";
const smtpPort = Number(process.env.SMTP_PORT || 587);
const smtpUser = process.env.SMTP_USER || "";
const smtpPass = process.env.SMTP_PASS || "";
const smtpFrom = process.env.SMTP_FROM || "no-reply@example.com";
let transporter: nodemailer.Transporter | null = null;
export const getTransporter = () => {
if (!transporter) {
if (!smtpHost || !smtpUser || !smtpPass) {
return null;
}
transporter = nodemailer.createTransport({
host: smtpHost,
port: smtpPort,
secure: smtpPort === 465,
auth: { user: smtpUser, pass: smtpPass },
});
}
return transporter;
};
export const sendResetPasswordEmail = async (to: string, link: string) => {
const t = getTransporter();
const subject = "Reset your Project Athena password";
const html = `
<p>You requested to reset your Project Athena password.</p>
<p>Click the link below to set a new password. If you didn't request this, you can ignore this email.</p>
<p><a href="${link}">Reset Password</a></p>
<p>This link will expire shortly for security reasons.</p>
`;
await t?.sendMail({ from: smtpFrom, to, subject, html });
};
export const sendInvitationEmail = async (to: string, link: string) => {
const t = getTransporter();
const subject = "You're invited to Project Athena";
const html = `
<p>You have been invited to join Project Athena.</p>
<p>Click the link below to set your password and activate your account.</p>
<p><a href="${link}">Accept Invitation</a></p>
<p>This link will expire shortly for security reasons.</p>
`;
await t?.sendMail({ from: smtpFrom, to, subject, html });
};