import { Resend } from "resend"; import { render } from "@react-email/render"; import { InvitationEmail } from "./templates/invitation"; function getResend(): Resend { const key = process.env.RESEND_API_KEY; if (!key) throw new Error("RESEND_API_KEY is not configured"); return new Resend(key); } export async function sendMagicLinkEmail({ email, url, token: _token, }: { email: string; url: string; token: string; }): Promise { const { error } = await getResend().emails.send({ from: process.env.EMAIL_FROM ?? "CubeAdmin ", to: email, subject: "Your CubeAdmin sign-in link", html: `

Click the link below to sign in to CubeAdmin. This link expires in 1 hour.

${url}

`, }); if (error) throw new Error(`Failed to send magic link email: ${error.message}`); } export async function sendInvitationEmail({ to, invitedByName, inviteUrl, role, }: { to: string; invitedByName: string; inviteUrl: string; role: string; }): Promise { const html = await render( InvitationEmail({ invitedByName, inviteUrl, role }), ); const { error } = await getResend().emails.send({ from: process.env.EMAIL_FROM ?? "CubeAdmin ", to, subject: `You've been invited to CubeAdmin`, html, }); if (error) throw new Error(`Failed to send email: ${error.message}`); }