mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-17 19:06:18 +02:00
♻️ Improve email abstraction (#863)
This commit is contained in:
parent
516a4114d0
commit
8cad515dc4
10 changed files with 751 additions and 152 deletions
|
@ -1,3 +1,4 @@
|
|||
import { EmailClient, SupportedEmailProviders } from "@rallly/emails";
|
||||
import { createProxySSGHelpers } from "@trpc/react-query/ssg";
|
||||
import * as trpc from "@trpc/server";
|
||||
import * as trpcNext from "@trpc/server/adapters/next";
|
||||
|
@ -7,6 +8,9 @@ import superjson from "superjson";
|
|||
import { randomid } from "../utils/nanoid";
|
||||
import { appRouter } from "./routers";
|
||||
|
||||
// Avoid use NODE_ENV directly because it will be replaced when using the dev server for e2e tests
|
||||
const env = process.env["NODE" + "_ENV"];
|
||||
|
||||
export async function createContext(
|
||||
opts: trpcNext.CreateNextContextOptions | GetServerSidePropsContext,
|
||||
) {
|
||||
|
@ -19,12 +23,30 @@ export async function createContext(
|
|||
opts.req.session.user = user;
|
||||
await opts.req.session.save();
|
||||
}
|
||||
|
||||
const emailClient = new EmailClient({
|
||||
openPreviews: env === "development",
|
||||
useTestServer: env === "test",
|
||||
provider: {
|
||||
name: (process.env.EMAIL_PROVIDER as SupportedEmailProviders) ?? "smtp",
|
||||
},
|
||||
mail: {
|
||||
from: {
|
||||
name: "Rallly",
|
||||
address:
|
||||
(process.env.NOREPLY_EMAIL as string) ||
|
||||
(process.env.SUPPORT_EMAIL as string),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
user,
|
||||
session: opts.req.session,
|
||||
req: opts.req,
|
||||
res: opts.res,
|
||||
isSelfHosted: process.env.NEXT_PUBLIC_SELF_HOSTED === "true",
|
||||
emailClient,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue