Openstatus
www.openstatus.dev
1import { getQueryClient, trpc } from "@/lib/trpc/server";
2import { EmailClient } from "@openstatus/emails";
3import Resend from "next-auth/providers/resend";
4import { getValidCustomDomain } from "../domain";
5
6export const ResendProvider = Resend({
7 apiKey: undefined,
8 async sendVerificationRequest(params) {
9 const url = params.url;
10 const email = params.identifier;
11
12 const emailClient = new EmailClient({
13 apiKey: process.env.RESEND_API_KEY ?? "",
14 });
15
16 const { prefix } = getValidCustomDomain(params.request);
17
18 if (!prefix) return;
19
20 const queryClient = getQueryClient();
21 const query = await queryClient.fetchQuery(
22 trpc.statusPage.validateEmailDomain.queryOptions({ slug: prefix, email }),
23 );
24
25 if (!query) return;
26
27 await emailClient.sendStatusPageMagicLink({
28 page: query.page.title,
29 link: url,
30 to: params.identifier,
31 });
32 },
33});