Singular (admin) account system

This commit is contained in:
Ahmed Al-Taiar
2024-08-14 12:35:57 -04:00
parent 544cea9105
commit b61a80c9a0
37 changed files with 1796 additions and 442 deletions

39
api/src/lib/email.ts Normal file
View File

@ -0,0 +1,39 @@
import * as nodemailer from 'nodemailer'
interface Options {
to: string | string[]
subject: string
html: string
text: string
}
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.GMAIL,
pass: process.env.GMAIL_SMTP_PASSWORD,
},
})
export async function sendEmail({ to, subject, text, html }: Options) {
return await transporter.sendMail({
from: `"${process.env.NAME} (noreply)" <${process.env.GMAIL}>`,
to: Array.isArray(to) ? to : [to],
subject,
text,
html,
})
}
export function censorEmail(email: string): string {
const [localPart, domain] = email.split('@')
if (localPart.length <= 2) return `${localPart}@${domain}`
const firstChar = localPart[0]
const lastChar = localPart[localPart.length - 1]
const middleLength = Math.min(localPart.length - 2, 7)
const middle = ''.repeat(middleLength)
return `${firstChar}${middle}${lastChar}@${domain}`
}