diff --git a/src/app/api/waitlist/route.ts b/src/app/api/waitlist/route.ts index 110c164..20d69e4 100644 --- a/src/app/api/waitlist/route.ts +++ b/src/app/api/waitlist/route.ts @@ -1,32 +1,32 @@ import { NextRequest, NextResponse } from 'next/server'; import nodemailer from 'nodemailer'; -interface WaitlistFormData { +interface WaitlistEntry { email: string; instagram?: string; tiktok?: string; + createdAt: string; } -// In-memory storage for demo purposes. Replace with database in production. -const waitlistDatabase: WaitlistFormData[] = []; - -// Configure your email service here const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST || 'smtp.gmail.com', port: parseInt(process.env.SMTP_PORT || '587'), - secure: process.env.SMTP_SECURE === 'true', // true for 465, false for other ports + secure: process.env.SMTP_SECURE === 'true', auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASSWORD, }, }); +const waitlistEntries: WaitlistEntry[] = []; + export async function POST(request: NextRequest) { try { - const body: WaitlistFormData = await request.json(); + const body = await request.json(); + const { email, instagram, tiktok } = body; // Validate email - if (!body.email || !body.email.includes('@')) { + if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { return NextResponse.json( { error: 'Invalid email address' }, { status: 400 } @@ -34,110 +34,91 @@ export async function POST(request: NextRequest) { } // Check if email already exists - if (waitlistDatabase.some(entry => entry.email === body.email)) { + if (waitlistEntries.some(entry => entry.email === email)) { return NextResponse.json( { error: 'Email already on waitlist' }, { status: 409 } ); } - // Add to database - waitlistDatabase.push(body); + // Create waitlist entry + const entry: WaitlistEntry = { + email, + instagram: instagram || undefined, + tiktok: tiktok || undefined, + createdAt: new Date().toISOString(), + }; + + waitlistEntries.push(entry); // Send confirmation email to user - const userEmailContent = ` - -
-Hi ${body.email.split('@')[0]},
-Thank you for joining our waitlist. You're now part of an exclusive group of creators and agencies who will get early access to Clearance.
-What to expect:
-Instagram: ${body.instagram}
` : ''} - ${body.tiktok ? `TikTok: ${body.tiktok}
` : ''} -We'll be in touch soon with more details!
-Best regards,
The Clearance Team
Hi ${email.split('@')[0]},
+Thank you for joining the Clearance waitlist! We're excited to have you on board.
+We'll be reaching out soon with early access to our platform. In the meantime, here's what you can expect:
+If you have any questions, feel free to reply to this email.
+Best regards,
The Clearance Team
Email: ${body.email}
- ${body.instagram ? `Instagram: ${body.instagram}
` : ''} - ${body.tiktok ? `TikTok: ${body.tiktok}
` : ''} -Submitted at: ${new Date().toISOString()}
-Total waitlist entries: ${waitlistDatabase.length}
-Email: ${email}
+Instagram: ${instagram || 'Not provided'}
+TikTok: ${tiktok || 'Not provided'}
+Submitted: ${new Date().toLocaleString()}
+