♻️ Improve email abstraction (#863)

This commit is contained in:
Luke Vella 2023-09-15 20:24:46 +01:00 committed by GitHub
parent 516a4114d0
commit 8cad515dc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 751 additions and 152 deletions

View file

@ -1,5 +1,4 @@
import { prisma } from "@rallly/database";
import { sendEmail } from "@rallly/emails";
import { absoluteUrl } from "@rallly/utils";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
@ -78,6 +77,7 @@ export const auth = router({
.mutation(
async ({
input,
ctx,
}): Promise<
| { ok: true; token: string }
| { ok: false; reason: "userAlreadyExists" | "emailNotAllowed" }
@ -107,7 +107,7 @@ export const auth = router({
code,
});
await sendEmail("RegisterEmail", {
await ctx.emailClient.sendTemplate("RegisterEmail", {
to: input.email,
subject: `${input.name}, please verify your email address`,
props: {
@ -168,6 +168,7 @@ export const auth = router({
.mutation(
async ({
input,
ctx,
}): Promise<
| { ok: true; token: string }
| { ok: false; reason: "emailNotAllowed" | "userNotFound" }
@ -193,7 +194,7 @@ export const auth = router({
code,
});
await sendEmail("LoginEmail", {
await ctx.emailClient.sendTemplate("LoginEmail", {
to: input.email,
subject: `${code} is your 6-digit code`,
props: {