Install resend package. Add convex/lib/resend.ts for sending emails via Resend API. Update convex/auth.ts to enable requireEmailVerification, sendVerificationEmail, and sendResetPassword handlers. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
31 lines
727 B
TypeScript
31 lines
727 B
TypeScript
const RESEND_API_KEY = process.env.RESEND_API_KEY!;
|
|
const RESEND_FROM_EMAIL = process.env.RESEND_FROM_EMAIL!;
|
|
|
|
interface SendEmailOptions {
|
|
to: string;
|
|
subject: string;
|
|
html: string;
|
|
}
|
|
|
|
export async function sendEmail({ to, subject, html }: SendEmailOptions) {
|
|
const response = await fetch('https://api.resend.com/emails', {
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: `Bearer ${RESEND_API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
from: RESEND_FROM_EMAIL,
|
|
to,
|
|
subject,
|
|
html,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.text();
|
|
throw new Error(`Failed to send email: ${error}`);
|
|
}
|
|
|
|
return response.json();
|
|
}
|