diff --git a/src/app.d.ts b/src/app.d.ts index e181dff..874ec16 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,7 +1,5 @@ // See https://svelte.dev/docs/kit/types#app.d.ts -import type { TwilioConfiguration } from '$lib/server/twilio'; - // for information about these interfaces declare global { namespace App { @@ -9,10 +7,6 @@ declare global { interface Locals { user: import('lucia').User | null; session: import('lucia').Session | null; - twilio: { - config: TwilioConfiguration; - client: import('twilio').Twilio; - }; } // interface PageData {} // interface PageState {} @@ -20,4 +14,4 @@ declare global { } } -export {}; +export {}; \ No newline at end of file diff --git a/src/hooks.server.ts b/src/hooks.server.ts deleted file mode 100644 index 19a15dc..0000000 --- a/src/hooks.server.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { TwilioConfig } from '$lib/server/twilio'; -import twilio from 'twilio'; - -export async function handle({ event, resolve }) { - const twilioConfig = TwilioConfig(); - const twilioClient = twilio(twilioConfig.twilio_account_sid, twilioConfig.twilio_auth_token); - event.locals.twilio = { - config: twilioConfig, - client: twilioClient, - }; - return await resolve(event); -} diff --git a/src/routes/app/sms/+page.server.ts b/src/routes/app/sms/+page.server.ts index bf9de3f..30f4ba9 100644 --- a/src/routes/app/sms/+page.server.ts +++ b/src/routes/app/sms/+page.server.ts @@ -1,6 +1,8 @@ import { PhoneRegex } from '$lib/regex'; import { logger } from '$lib/server/logger'; +import { TwilioConfig } from '$lib/server/twilio'; import { fail, type Actions } from '@sveltejs/kit'; +import twilio from 'twilio'; import zod from 'zod'; export const actions = { @@ -29,12 +31,17 @@ export const actions = { return fail(400, { error: 'invalid_message' }); } - const twilio = event.locals.twilio; + const twilioConfig = TwilioConfig(); + const twilioClient = twilio( + twilioConfig.twilio_account_sid, + twilioConfig.twilio_auth_token + ); + try { - const result = await twilio.client.messages.create({ + const result = await twilioClient.messages.create({ to: phone, body: message, - from: twilio.config.twilio_phone_number, + from: twilioConfig.twilio_phone_number, }); logger.debug(result); } catch (e) { @@ -45,4 +52,4 @@ export const actions = { success: true, }; }, -} satisfies Actions; +} satisfies Actions; \ No newline at end of file diff --git a/src/routes/app/sms/+page.svelte b/src/routes/app/sms/+page.svelte index 939a807..76341e4 100644 --- a/src/routes/app/sms/+page.svelte +++ b/src/routes/app/sms/+page.svelte @@ -64,4 +64,4 @@ .page { @apply flex flex-col items-center justify-around gap-24 py-[10%]; } - + \ No newline at end of file