feat: add editorial registration and authentication
This commit is contained in:
1 parent
7acaacb92e
commit
9b22752ef2
20 files changed
+1728
-20
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import "server-only";
|
||||
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
import { env } from "@/config/env";
|
||||
|
||||
export type MailMessage = {
|
||||
from: string;
|
||||
to: string;
|
||||
subject: string;
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type MailTransport = {
|
||||
sendMail(message: MailMessage): Promise<unknown>;
|
||||
};
|
||||
|
||||
export type Mailer = {
|
||||
sendVerification(input: { to: string; verificationUrl: string }): Promise<void>;
|
||||
sendPasswordReset(input: { to: string; resetUrl: string }): Promise<void>;
|
||||
sendApprovalNotice(input: { to: string; editorialName: string }): Promise<void>;
|
||||
};
|
||||
|
||||
export function createMailer({ from, transport }: { from: string; transport: MailTransport }): Mailer {
|
||||
async function send(message: Omit<MailMessage, "from">): Promise<void> {
|
||||
await transport.sendMail({ from, ...message });
|
||||
}
|
||||
|
||||
return {
|
||||
async sendVerification({ to, verificationUrl }) {
|
||||
await send({
|
||||
to,
|
||||
subject: "Bitte bestätigen Sie Ihre E-Mail-Adresse",
|
||||
text: `Bitte bestätigen Sie Ihre E-Mail-Adresse für das Redaktionsportal:\n\n${verificationUrl}`,
|
||||
});
|
||||
},
|
||||
async sendPasswordReset({ to, resetUrl }) {
|
||||
await send({
|
||||
to,
|
||||
subject: "Passwort für das Redaktionsportal zurücksetzen",
|
||||
text: `Setzen Sie Ihr Passwort für das Redaktionsportal zurück:\n\n${resetUrl}`,
|
||||
});
|
||||
},
|
||||
async sendApprovalNotice({ to, editorialName }) {
|
||||
await send({
|
||||
to,
|
||||
subject: "Ihr Zugang zum Redaktionsportal ist freigegeben",
|
||||
text: `Der Zugang für ${editorialName} wurde freigegeben. Sie können sich jetzt im Redaktionsportal anmelden.`,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const smtpTransport = nodemailer.createTransport({
|
||||
host: env.SMTP_HOST,
|
||||
port: env.SMTP_PORT,
|
||||
secure: env.SMTP_PORT === 465,
|
||||
auth: {
|
||||
user: env.SMTP_USER,
|
||||
pass: env.SMTP_PASSWORD,
|
||||
},
|
||||
});
|
||||
|
||||
export const mailer = createMailer({ from: env.SMTP_FROM, transport: smtpTransport });
|
||||
Reference in new issue
Block a user