Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/app/api/sms/send-notification/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*/

import { NextResponse } from 'next/server';
import { withAuth } from '@/lib/api/middleware/auth.js';
import { TwilioSMSProvider } from '@/lib/services/twilio-sms-provider.js';

/**
* Send SMS notification
* @param {Object} params - SvelteKit request parameters
* @param {Request} params.request - The request object
* Send SMS notification (requires authentication)
*/
export async function POST(request) {
export const POST = withAuth(async ({ request }) => {
try {
const { phoneNumber, message } = await request.json();

Expand All @@ -30,18 +29,18 @@ export async function POST(request) {

// Initialize Twilio SMS provider
const twilioProvider = new TwilioSMSProvider();

// Send SMS via Twilio
const result = await twilioProvider.sendSMS(phoneNumber, message);

const messageId = (result && typeof result === 'object' && 'messageId' in result) ? result.messageId : 'unknown';
const status = (result && typeof result === 'object' && 'status' in result) ? result.status : 'sent';

console.log('📱 [SMS-API] SMS sent successfully:', {
messageId,
status
});

return NextResponse.json({
success: true,
messageId,
Expand All @@ -56,4 +55,4 @@ export async function POST(request) {
{ status: 500 }
);
}
}
});
Loading