19 lines
668 B
TypeScript
19 lines
668 B
TypeScript
import "server-only";
|
|
|
|
const FROM = "Buzz Guide <[email protected]>";
|
|
|
|
export async function sendAuthEmail(to: string, subject: string, text: string): Promise<void> {
|
|
const apiKey = process.env.RESEND_API_KEY;
|
|
if (!apiKey) throw new Error("RESEND_API_KEY is required for authentication email.");
|
|
|
|
const response = await fetch("https://api.resend.com/emails", {
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${apiKey}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ from: FROM, to: [to], subject, text }),
|
|
});
|
|
if (!response.ok) throw new Error(`Authentication email delivery failed (${response.status}).`);
|
|
}
|