From efb0237145d455ce609fd274847a57edb2f899bd Mon Sep 17 00:00:00 2001 From: Gabriel Brown Date: Sun, 21 Jun 2026 21:51:41 -0500 Subject: [PATCH] Update stuff so we can pass build hopefully --- .../convex/custom/auth/providers/usesend.ts | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/backend/convex/custom/auth/providers/usesend.ts b/packages/backend/convex/custom/auth/providers/usesend.ts index c0b94aa..ae2b68b 100644 --- a/packages/backend/convex/custom/auth/providers/usesend.ts +++ b/packages/backend/convex/custom/auth/providers/usesend.ts @@ -1,7 +1,39 @@ import type { EmailConfig, EmailUserConfig } from '@auth/core/providers/email'; import { generateRandomString, RandomReader } from '@oslojs/crypto/random'; import { alphabet } from 'oslo/crypto'; -import { UseSend } from 'usesend-js'; + +type UseSendEmailPayload = { + from: string; + to: string[]; + subject: string; + text: string; + html: string; +}; + +const sendUseSendEmail = async ( + apiKey: string, + useSendUrl: string, + payload: UseSendEmailPayload, +) => { + const response = await fetch(`${useSendUrl}/api/v1/emails`, { + method: 'POST', + headers: { + Authorization: `Bearer ${apiKey}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + let errorBody: unknown; + try { + errorBody = await response.json(); + } catch { + errorBody = response.statusText; + } + throw new Error(`UseSend error: ${JSON.stringify(errorBody)}`); + } +}; export default function UseSendProvider(config: EmailUserConfig): EmailConfig { return { @@ -32,13 +64,11 @@ export default function UseSendProvider(config: EmailUserConfig): EmailConfig { throw new Error('USESEND_API_KEY and USESEND_URL must be set.'); } - const useSend = new UseSend(apiKey, useSendUrl); - // For password reset, we want to send the code, not the magic link const isPasswordReset = url.includes('reset') || provider.id.includes('reset'); - const result = await useSend.emails.send({ + await sendUseSendEmail(apiKey, useSendUrl, { from: provider.from ?? 'noreply@example.com', to: [to], subject: isPasswordReset @@ -70,10 +100,6 @@ export default function UseSendProvider(config: EmailUserConfig): EmailConfig { `, }); - - if (result.error) { - throw new Error('UseSend error: ' + JSON.stringify(result.error)); - } }, options: config,