Remove unauthenticated /send email endpoint
This commit is contained in:
@@ -5,7 +5,6 @@ GOOGLE_CLIENT_ID=6
|
|||||||
GOOGLE_CLIENT_SECRET=
|
GOOGLE_CLIENT_SECRET=
|
||||||
RESEND_API_KEY=
|
RESEND_API_KEY=
|
||||||
EMAIL_FROM=
|
EMAIL_FROM=
|
||||||
RESEND_TEMPLATE_ID=
|
|
||||||
# Optional. Resend template for the admin "set your password" invite email.
|
# Optional. Resend template for the admin "set your password" invite email.
|
||||||
# Defaults to `registration-email`. Expected variables:
|
# Defaults to `registration-email`. Expected variables:
|
||||||
# `target_email_address`, `registration_link`.
|
# `target_email_address`, `registration_link`.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function getResend(): Resend {
|
|||||||
* @example
|
* @example
|
||||||
* await sendMail({
|
* await sendMail({
|
||||||
* to: 'jane@example.com',
|
* to: 'jane@example.com',
|
||||||
* templateId: 'tmpl_abc123', // optional — defaults to RESEND_TEMPLATE_ID
|
* templateId: 'tmpl_abc123', // required — Resend template id or alias
|
||||||
* subject: 'Your license key is ready', // optional — defaults to 'Template Email'
|
* subject: 'Your license key is ready', // optional — defaults to 'Template Email'
|
||||||
* data: { // optional — template variables
|
* data: { // optional — template variables
|
||||||
* firstName: 'Jane',
|
* firstName: 'Jane',
|
||||||
@@ -40,7 +40,7 @@ function getResend(): Resend {
|
|||||||
export async function sendMail(options: {
|
export async function sendMail(options: {
|
||||||
to: string;
|
to: string;
|
||||||
subject?: string;
|
subject?: string;
|
||||||
templateId?: string;
|
templateId: string;
|
||||||
data?: Record<string, string | number>;
|
data?: Record<string, string | number>;
|
||||||
}) {
|
}) {
|
||||||
const { to, subject, templateId, data } = options;
|
const { to, subject, templateId, data } = options;
|
||||||
@@ -50,7 +50,7 @@ export async function sendMail(options: {
|
|||||||
to: [to],
|
to: [to],
|
||||||
subject: subject ?? 'Template Email',
|
subject: subject ?? 'Template Email',
|
||||||
template: {
|
template: {
|
||||||
id: templateId ?? env.RESEND_TEMPLATE_ID,
|
id: templateId,
|
||||||
variables: data ?? {}
|
variables: data ?? {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
/** src/routes/send/+server.ts
|
|
||||||
* AUTHOR: Neil Clack
|
|
||||||
* EMAIL: nclack@radiantwavetech.com
|
|
||||||
* DATE: 07/06/2027
|
|
||||||
*
|
|
||||||
* An example endpoint, temporarily enabled, to describe
|
|
||||||
* how to send an email with the Resend API and our custom
|
|
||||||
* sendMail function.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { sendMail } from '$lib/server/resend';
|
|
||||||
import type { RequestHandler } from './$types';
|
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ request }) => {
|
|
||||||
const { to, subject, templateId, data } = await request.json();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await sendMail({ to, subject, templateId, data });
|
|
||||||
return json(result);
|
|
||||||
} catch (e) {
|
|
||||||
return json({ error: (e as Error).message }, { status: 400 });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user